














































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A lecture note from cs101 introduction to computing, focusing on algorithms, their building blocks (sequences, conditionals, loops), and the representation techniques (pseudo code and flowcharts). The lecture also covers the conversion of decimal numbers to binary using these techniques.
Typology: Slides
1 / 54
This page cannot be seen from the preview
Don't miss anything!















































Algorithms II
Focus of the last lecture was on Algorithms
Became familiar with the concept of algorithms:
Algorithm Building Blocks
All problems can be solved by employing any one of the following building blocks or their combinations
5
Start or stop
Process
Input or output
Connector
Decision
Flow line
Off-page connector
Review of
Flowchart
Elements
Sequences
A sequence of instructions that are executed in the precise order they are written in:
statement block 1 statement block 2 statement block 3
7
statement block 1
statement block 2
statement block 3
Conditionals
Select between alternate courses of action depending upon the evaluation of a condition
If ( condition = true )
statement block 1
Else
statement block 2
End if
8
statement block 1
condition
True False
statement block 2
We will now present the algorithm for a problem whose solution is familiar to us
We will first go through the problem statement and then present the algorithm in three different formats:
Problem Statement
Convert a decimal number into binary
We did write down the pseudo code for this problem last time
Lets do it again, and in a slightly more formal way
Solution in Pseudo Code
Determine the quotient & remainder of x ÷ 2 y = CONCATENATE( remainder, y ) x = quotient }
Tips on Writing Good Pseudo Code
17
Start
Find quotient & remainder of x ÷ 2
Get x
x >0?
Print y
Stop
y = CONC(remainder, x ) x = quotient
x is the decimal number y is the binary equivalent
Flowchart of Decimal to Binary Conversion
Yes
No
NOTE: Don’t worry if you don’t understand this code for now; you will - later!Docsity.com
Another Example: Sorting
Sort the following objects w.r.t. their heights