Introduction To Algorithm: Agenda
Introduction To Algorithm: Agenda
L-02
AGENDA:
❑Introduction to Algorithm
What is
Algorithm?
Problem − Design an algorithm to add two numbers and display the result.
Quick Sort
Heap Sort
Insertion Sort
TIME SPACE
Time Vs Space
P P
A1 A2 A3 A1 A2 A3
A1 is BEST A2 is BEST
Computing Time Complexity
Traditional Approach
1. Convert the Algorithm to its equivalent program using a programming
language like C, C++, Java, Python, etc
2. Run the program on a platform
3. Compute the execution time by using the following formulae
Texec = Tend - Tstart
P
A1 A2 Algorithms
P1 in C P2 in C++ Programs
5n1
Linear
• Total number of key operation = Approx. time of execution
Linear Time Algorithm
• Texec = 5n Linear Time
Algorithm
• Texec ∝ n
• T1= 5n +10
Linear Time
• T2 = 100n +20
Algorithm
• T3 = 19n
Quadratic Time Algorithm
• T4 = n2 + 5n + 3
• T5 = 6n2 + 7n +10
• T6 = 5n2
• T7 = 2n2 + 8
Logarithmic Time Algorithm
• T1 = logn
• T2 = 2logn + 5
Exponential Time Algorithm
• T1 = 2n +3
• T 2 = 3n
• T 3 = 5n + 6 Kn Where K is Constant
• T4 = 22n
Constant Time Algorithm
• T1 = 5
• T2 = 100
• T3 = 1000
• T4 = 100000000000
• T5 = 100000000000000000000000000000
Classification of Algorithm