Course Notes — DSA
Running notes for a Data Structures & Algorithms course — concepts, analysis methods, and worked examples.
Running notes for a Data Structures & Algorithms course — concepts, analysis methods, and worked examples.
Running notes for a Data Structures and Algorithms course. Updated as topics progress.
A Computational Problem asks for a solution in terms of an Algorithm.
The Algorithm maps a set of instances or cases to a possibly empty set of solutions — so a computational problem is a relation that maps instances to solutions.
The behavior of algorithms is described using model of computations, which specify how an algorithm handles input/output and what operations it may perform. This course uses the RAM Model of Computation.
Formally, an algorithm solves a computational problem if:
A Data Structure stores and organizes data for efficient algorithm access.
While analyzing an algorithm, we evaluate its efficiency and correctness. The algorithm should:
To analyze at an abstract level, we count primitive operations — each defined to run in time on the RAM model:
We study running time as a function of input size . Three asymptotic notations bound growth:
if there exist constants and such that:
We say grows no faster than .
if there exist constants and such that:
We say grows at least as fast as .
if and .
and grow at the same rate up to constant factors.
| Class | Name | Typical algorithm |
|---|---|---|
| Constant | Array access, hash lookup | |
| Logarithmic | Binary search, balanced BST ops | |
| Linear | Linear scan, BFS | |
| Linearithmic | Merge sort, heap sort | |
| Quadratic | Insertion sort, bubble sort | |
| Cubic | Matrix multiplication (naive) | |
| Exponential | Subset enumeration | |
| Factorial | Permutation enumeration |
Works well for small or nearly-sorted data. Inner loop is tight and cache-friendly.
Divide-and-conquer: split in half, sort each half, merge. The merge step takes ; the recurrence is , which solves to by the Master Theorem.
Build a max-heap in , then extract-max times in each.
| Structure | Access | Search | Insert | Delete |
|---|---|---|---|---|
| Array | ||||
| Linked List | ||||
| Stack / Queue | ||||
| Hash Table | — | avg | avg | avg |
| AVL Tree | ||||
| Heap | — |