Lecture 2
Lecture 2
3
Properties of algorithms
Input: what the algorithm takes in as input
Output: what the algorithm produces as output
Definiteness/unambigious
Read
Read a,b
Correctness
Finiteness: while(1)
{-------
}
Effectiveness:
Start
Read a,b
Read c
Sum=a+b
Print sum
End
4
Why algorithm?
5
Algorithm and programs
• Algorithms:
– use natural language
– written by domain expert
– Software and hardware independent
– Analyze algorithms
6
Algorithm representation
Pseudo code
Flowchart
7
ALGORITHM TO FIND THE AREA OF A RECTANGLE
How to write a algorithm
The problem that is to be Add 3 numbers and print
solved their sum.
The numbers must
The constraints of the contain only digits and
problem no other characters
The input to be taken The three numbers to be
added.
The output to be expected The sum of the three
The solution to this problem numbers taken as the
output.
The solution consists of
adding the 3 numbers. It
can be done with the help
of ‘+’ operator, or bit-wise
Algorithm to add three numbers
• Start
• Get input
Read num1 num2 num3
• Calculate sum
sum = num1 + num2+num 3
• Display output
• Print sum
• End
ALGORITHM TO FIND THE LARGEST OF
THREE NUMBERS
ALGORITHM TO FIND THE LARGEST OF
THREE NUMBERS
References
1)https://depositphotos.com/27462911/sto
ck-photo-flow-chart-diagram.html
2)https://www.geeksforgeeks.org/introduct
ion-to-algorithms/
3) https://en.wikipedia.org/wiki/Algorithm
Thank You