ALGORITHMS – COMPLETE STUDY GUIDE
Comprehensive Lecture Notes with Examples & Exam Tips
1. WHAT IS AN ALGORITHM?
A step-by-step procedure for solving a problem in a finite number of steps. Every algorithm must
have:
· Input: Zero or more values.
· Output: At least one result.
· Definiteness: Every step is clear and unambiguous.
· Finiteness: It must terminate after a finite number of steps.
· Effectiveness: Each step is basic enough to be carried out manually.
---
2. ANALYZING ALGORITHMS: TIME & SPACE COMPLEXITY
We measure efficiency, not execution time, because the same algorithm runs differently on
different hardware.
Big O Notation (Worst-Case)
Describes the upper bound of growth rate as input size grows.
Notation Name Example
O(1) Constant Array access by index
O(log n) Logarithmic Binary search
O(n) Linear Linear search
O(n log n) Linearithmic Merge sort, Quick sort (avg)
O(n²) Quadratic Bubble sort, Selection sort
O(2ⁿ) Exponential Brute-force subset generation
Key rule: Drop constants and lower-order terms. O(2n + 5) = O(n).
---
Comprehensive Lecture Notes with Examples & Exam Tips
1. WHAT IS AN ALGORITHM?
A step-by-step procedure for solving a problem in a finite number of steps. Every algorithm must
have:
· Input: Zero or more values.
· Output: At least one result.
· Definiteness: Every step is clear and unambiguous.
· Finiteness: It must terminate after a finite number of steps.
· Effectiveness: Each step is basic enough to be carried out manually.
---
2. ANALYZING ALGORITHMS: TIME & SPACE COMPLEXITY
We measure efficiency, not execution time, because the same algorithm runs differently on
different hardware.
Big O Notation (Worst-Case)
Describes the upper bound of growth rate as input size grows.
Notation Name Example
O(1) Constant Array access by index
O(log n) Logarithmic Binary search
O(n) Linear Linear search
O(n log n) Linearithmic Merge sort, Quick sort (avg)
O(n²) Quadratic Bubble sort, Selection sort
O(2ⁿ) Exponential Brute-force subset generation
Key rule: Drop constants and lower-order terms. O(2n + 5) = O(n).
---