Page 1
Wink Notes
B.Tech CSE — 4th Semester
Design and Analysis of Algorithms
— Unit - 1 —
1. Introduction to Algorithm Analysis
An algorithm is a finite sequence of unambiguous instructions to solve a specific problem. However, there are often dozens of different algorithms that solve the exact same problem (e.g., sorting an array). How do we mathematically prove which one is 'better'?
1.1 The Problem with Physical Time
We cannot simply run two algorithms and measure their execution time in seconds using a stopwatch. Execution time in seconds is highly dependent on hardware.
- A terrible sorting algorithm (Bubble Sort) running on a modern 5GHz supercomputer might finish in 0.1 seconds.
- A brilliant sorting algorithm (Merge Sort) running on a 1990s Pentium processor might take 5.0 seconds.
If we only looked at physical time, we would incorrectly conclude Bubble Sort is better. Therefore, algorithm analysis must be hardware-independent.
1.2 The RAM Model of Computation
To mathematically analyze an algorithm, we assume a generic, hypothetical computer called the Random Access Machine (RAM).
- Instructions are executed sequentially, one at a time.
- Every basic operation (addition, assignment, boolean comparison) takes exactly 1 constant unit of time ().
- Memory access takes exactly 1 constant unit of time.
- Memory is infinite.