Algorithm Analysis – Detailed Notes 1.
Applications of Algorithm Analysis Algorithm analysis helps
determine how efficiently an algorithm performs in terms of time and memory. It is essential because it
allows programmers to compare different approaches to solving a problem, predict performance, and
select the most optimal solution. Key applications include: Measuring execution time and memory
usage. Comparing two or more algorithms to select the best one. Predicting program behavior for large
inputs. Improving and optimizing existing algorithms. Ensuring scalability of systems and applications.
2. Efficiency of Algorithms Efficiency describes how well an algorithm uses resources: Time
Efficiency: How long it takes to run. Space Efficiency: How much memory it uses. The goal is to
design algorithms that take the least amount of time and use minimal memory while solving the
problem correctly. 3. Asymptotic Notations Asymptotic notations describe the growth rate of an
algorithm’s running time as input size increases. Big-O (O): Upper bound; describes worst-case time
complexity. Omega (Ω): Lower bound; represents best-case performance. Theta (Θ): Tight bound;
gives both upper and lower bounds, representing exact growth rate. 4. Time Complexity Using O
Notation Big-O notation shows how time increases relative to input size n. Common complexities: O(1):
Constant time O(log n): Logarithmic time (Binary Search) O(n): Linear time O(n log n): Efficient sorting
algorithms O(n²): Nested loops O(2■): Exponential algorithms O(n!): Factorial algorithms 5.
Polynomial vs Exponential Algorithms Polynomial Algorithms: Have complexities like n, n², n³, n log
n. They are efficient and scale well. Exponential Algorithms: Have complexities like 2■, 3■. They
grow extremely fast and are impractical for large inputs. 6. Best, Average, and Worst Case
Complexities Best Case: The minimum time an algorithm takes (e.g., finding element at index 1 in
linear search → O(1)). Average Case: Expected time for typical inputs (linear search → O(n/2) ≈ O(n)).
Worst Case: Maximum time algorithm may take (e.g., searching the last element → O(n)). 7. Analyzing
Recursive Programs Recursive algorithms are analyzed using recurrence relations. For example: T(n)
= T(n/2) + 1 → O(log n) Common patterns: Divide and Conquer: Merge Sort → O(n log n) Tree
Recursion: Fibonacci → O(2■) Linear Recursion: Factorial → O(n) Methods to solve recurrence
relations: Substitution Method Recursion Tree Method Master Theorem