Programming core
Algorithms
5 self-contained study topics — notes, diagrams, formulas, and worked examples for exams and GATE.
Topics
- Asymptotic ComplexityAsymptotic notation describes how running time grows with input size, ignoring constants; Big-O is an upper bound, Ω a lower bound, and Θ a tight bound, while the Master theorem solves the common divide-and-conquer recurrences.
- Sorting and SearchingComparison sorts are bounded below by O(n log n), achieved by merge sort and heap sort and by quicksort on average; binary search then finds an element in a sorted array in O(log n) by halving the range each step.
- Greedy AlgorithmsA greedy algorithm builds a solution by making the locally best choice at each step; it is optimal only when the problem has the greedy-choice property and optimal substructure, as in activity selection, Huffman coding and Kruskal’s MST.
- Dynamic ProgrammingDynamic programming solves problems with overlapping subproblems and optimal substructure by storing each subproblem’s result once; it can be top-down (memoised recursion) or bottom-up (tabulation), turning exponential recursion into polynomial time.
- Graph AlgorithmsShortest-path algorithms differ by graph type: Dijkstra is fastest for non-negative weights, Bellman-Ford tolerates negatives and detects negative cycles, and Floyd-Warshall computes all-pairs distances in O(V³).