Sie sind auf Seite 1von 33


Spring 2017 CS 101 Introduction To Computing

Let Us C 13th Edition, BPB Publications, July 2016
Yashavant Kanetkar
 B1
 An Introduction to Bioinformatics Algorithms By Neil C. Jones and Pavel A.
Pevzner, MIT Press
Emailed notes: “AlgorithmsAndPseudocodeFromPevznerBook.pdf”
Watch (for those interacting with a computer first time):

At the end of sides
What is a Computer
 A computer is an electronic device that manipulates
information, or data.
 It has the ability to store, retrieve, and process data.
 You may already know that you can use a computer to type
documents, send email, play games, and browse the Web.
 You can also use it to edit or
create spreadsheets, presentations, and even videos.
 Hardware vs. Software
A little video
Why do we need a programming Language?
 We understand English/Hindi/Malayalam/Telugu
 Computer understands C/C++/Java (Programming Languages)
Generations of Programming Languages

Generation First Second Third Fourth

00010 {
LDA 34 ADD color : red;
Code example 00001 x=x+1
#1 STO 34 font-style : italic

(HIGH) Visual
(LOW) Machine (LOW) (HIGH) SQL, CS
Language Basic, C, python
Code Assembly Code S, Haskell etc.
First Generation
 Just zero and ones 1010101001100010
 Fed through punch card etc.
 No need to translate – directly understandable by computer, hence,
 Object code or machine code.
 Difficult to understand /update/edit by human.
Second Generation
 Assembly Language
 Mnemonic codes

Assembly Code Object Code

LDA A ADD #5 STA A JMP 001000000101
-> Assembler ->
#3 001100110100
Third Generation (High Level Languages)
 Programmer-friendly features to code such as loops, conditionals,
classes etc.
 One line of third generation code can produce many lines of object
(machine) code, saving a lot of time when writing programs.
 Code are imperative: code is executed line by line, in sequence.
 Hardware independence, can be easily ported to other systems and
 Requires a Compiler or an Interpreter.
 Not possible with 1st and 2nd gen because they were machine dependent

 Time saving, programmer friendly, one line of 3rd gen is the

equivalent of many lines of 1st and 2nd gen
Fourth Generation
 Designed to reduce programming effort and the time it takes to
develop software
 Designed with a specific purpose in mind
 Query databases (SQL)
 Make reports (Oracle Reports)

 Construct user interface (XUL)

 What computation should be performed and not how to perform it.
--an example of a Structured Query Language (SQL) to
select criminal details from a database
SELECT name, height, DoB FROM criminals WHERE numScars = 7;
C Language
 Developed at AT & T’s Bell Laboratories of USA in 1972
 Designed and written by a man named Dennis Ritchie
 Third generation high level language.
 A typical programming task can be divided into two phases:
 Problem solving phase
 Produce an ordered sequence of steps that describe solution of problem
 An algorithm
 Implementation phase
 implement the program in some programming language
 Example 1: Write an algorithm to determine a student’s final grade
and indicate whether it is passing or failing. The final grade is
calculated as the average of four marks.

 Input a set of 4 marks

 Calculate their average by summing and dividing by 4
 if average is below 50
Print “FAIL”
Print “PASS”
 Similar to algorithm but more programming language like yet
independent of any particular programming language

Input M1,M2,M3,M4
GRADE  (M1+M2+M3+M4)/4
if (GRADE < 50) then
Print “FAIL”
Print “PASS”
Pseudocode Constructs
 A variable, written as x or total, contains some numerical value and
can be assigned a new numerical value at different points throughout
the course of an algorithm.
 An array of n elements is an ordered collection of n variables a1, a2, .
. . , an.
 In a = (a1, a2, . . . , an), a is the array and the individual elements are
denoted as ai, where i is between 1 and n.
 Write a pseudocode to calculate two roots of a quadratic expression
 Write a pseudocode to find the largest among n numbers.
 Graphical representation of any program is called flowchart.
 There are some standard graphics that are used in flowchart as
 Make a flowchart to input temperature, if temperature is less than 32
then print "below freezing" otherwise print "above freezing"?
 Draw a flowchart to check if a number is divisible by 5 and greater
than 100.
 Draw a flowchart to check if a number is prime.
 Draw a flow chart to find factorial of a number.
Assignment Problems
 Write pseudocode and draw a flowchart for the following problems
1. To swap two numbers.
2. To calculate simple and compound interest.
3. To find second largest numbers in a list of n numbers
4. To check if the given year is a leap year
5. In a list of n>4 positive numbers, print first four numbers less than
100. If four such numbers are not found, print appropriate message.