2. Algorithm
A finite set of statements that guarantees an optimal solution for logical and
mathematical problems in finite interval of time.
Example Problem : Average of 2 numbers
Algorithm Source Code in ‘C’
1. Declare Variables int a,b, add;
2. Get input scanf(“%d %d” &a, &b);
3. Find average and assign the value average= (a+b)/2;
4. Display output result printf(“%d”,average);
No. of Statements = 4
Optimal Solution = average of 2 numbers
Dr. Kuppusamy P
3. Characteristics of Algorithm
• Input: Zero or more quantities which are externally
supplied.
• Output: At least one quantity is generated.
• Finiteness: Execution terminates after a finite number of
steps for all possible inputs.
• Definiteness: Each step must be clear and unambiguous.
• Effectiveness: Every step must be given enough
information to produce results.
Dr. Kuppusamy P
4. Measure the performance of Algorithms
• Time Complexity
• Space Complexity
- Computational resources (time complexity) is
usually more important than space complexity
Good Algorithms Should:
▪ Run in less time i.e. Less Time Complexity
▪ Consume less memory i.e. Less Space
Complexity
Dr. Kuppusamy P
5. References
Dr. Kuppusamy P
• Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein,
“Introduction to Algorithms”, MIT Press.