Lecture # 01_new
Lecture # 01_new
Algorithm
Hilal Jan
algorithms
Introduction
Procedure:Metho
Mix the sugar,d baking powder and flour, mix in
beaten eggs, melted butter and bake at 325F for
40 mins.
Outpu
Result:t
Department of Computer Science
What is
Algorithm?
What is binary equivalent of decimal integer
75?
1001011
How can we convert this number into its
binary equivalent?
We have a procedure for this.
Let us see how we convert 75 into binary
1001011
Department of Computer Science
Procedure for Decimal to Binary
conversion
1. Write the decimal number
2. Divide by 2; write quotient and remainder
3. Repeat step 2 on the quotient; keep on repeating until
the quotient becomes zero
4. Write all remainder digits in the reverse order (last
remainder first) to form the final result
What is it?
A procedural solution to given problem
Briefly speaking, algorithms are
procedural solutions to problems
Algorithms are not answers, but rather
precisely defined procedures for getting
answers. (e.g., sorting 3 numbers)
Department of Computer Science
Formal
Definition
proble
m
algorithm
Is there a
relationship
between input
and output?
L
o
g
i
c
Algorithm= Data +
Logic
m
n
Upshot
Process
Input or output
Flowchar Decision
t Flow line
Symbols Connector
Off-page connector
Flowchar
t counter
Automatic-
Symbols counter loop
A
S
B
situation is used:
1.
number Input
Number
Base Step 1
2. Divide by 2; write
quotient and remainder Quatient=Number / Base
Remainder = Number %
Base
2. Divide by 2; write
quotient and
remainder