Comparing Algorithms
Comparing Algorithms
Challenges:
Asymptotic Analysis
Count the number of basic steps an algorithm performs for input of size n.
Example:
Input Examples:
1. Factorial Calculation: Requires just one number as input.
Sorting Example:
Example:
As input size increases, Merge Sort becomes much faster than Insertion
Sort.
Even with a slower computer, a better algorithm (like Merge Sort) can
outperform.
3. Add for Sequential Parts: Total cost is the sum of steps in sequence.
For Loops:
Nested Loops:
While Loops: