- Home
- Design & Analysis of Algorithms
Design & Analysis of Algorithms
Step-by-step recipes for solving problems efficiently: sorting, searching, graphs, greedy algorithms, dynamic programming and backtracking — with their time complexity.
Binary Search
Find any item in a sorted list of a million in about 20 steps by halving the search space every time. Watch it in 3D.
Bubble Sort
The simplest sorting algorithm — compare neighbours, swap if they're out of order, repeat. Watch the big values bubble to the end in 3D.
Selection Sort
Find the smallest value, swap it to the front, repeat. Always O(n²) comparisons, but never more than n − 1 swaps.
Insertion Sort
Sort the way you sort playing cards — pick up one card at a time and slide it into place. Fast on almost-sorted data.
Merge Sort
Divide and conquer in action. In 3D, every level of recursion literally steps towards you — then the pieces merge back in sorted order.
Quick Sort
Pick a pivot, split the array into "smaller" and "bigger", and the pivot lands in its final spot. See the partition happen in 3D.
Heap Sort
Build a max-heap, then repeatedly move the biggest element to the end. Guaranteed O(n log n) with no extra memory — see the tree and the array change together.
Counting Sort & Radix Sort
Sorting without comparing. Counting sort uses values as positions, and radix sort repeats it digit by digit, beating the O(n log n) limit.
Graph Traversal — BFS & DFS
Two ways to explore every node of a graph. BFS spreads out like ripples using a queue; DFS dives deep like a maze explorer using a stack. Compare them on a real 3D graph.
Topological Sort
Put tasks in an order that respects every "do this first" arrow. Kahn's algorithm and DFS both do it in O(V + E), and both catch cycles.
Dijkstra's Shortest Path
How maps find the cheapest route. Watch distances shrink as Dijkstra's algorithm relaxes edges on a 3D weighted graph.
Bellman–Ford Algorithm
Shortest paths even when some edges are negative. Relax every edge V − 1 times, then one extra pass catches negative cycles.
Minimum Spanning Tree — Prim & Kruskal
Connect every node with the cheapest total edge weight. Compare Kruskal's "cheapest edge first" with Prim's "grow one tree" on a 3D graph.
Floyd–Warshall (All-Pairs Shortest Paths)
Find the shortest distance between every pair of nodes with three simple loops. Watch the distance matrix improve as each node becomes an allowed stop-over.
0/1 Knapsack (Dynamic Programming)
Choose items to maximise value without exceeding a weight limit. Watch the DP table fill up as a 3D bar chart and trace back the chosen items.
Longest Common Subsequence (LCS)
Find the longest sequence of letters that appears, in order, in two strings. A classic dynamic programming problem behind diff tools and DNA comparison.
Matrix Chain Multiplication
(AB)C and A(BC) give the same matrix but can cost very different amounts of work. Dynamic programming finds the cheapest brackets.
Huffman Coding
Compress text by giving frequent characters short codes. Watch the greedy algorithm merge the two rarest groups again and again into a 3D tree.
KMP String Matching
Find a pattern in a text without ever reading a character twice. The LPS table tells the pattern how far it can jump after a mismatch.
N-Queens (Backtracking)
Place N queens on a chessboard so none attack each other. Watch backtracking try, fail and undo moves on a 3D board.
Edit Distance (Levenshtein)
How many inserts, deletes and replacements turn one word into another? Fill a dynamic-programming table to find the minimum.
Activity Selection (Greedy)
Attend as many non-overlapping events as possible. Sort by finish time and always take the earliest finisher that fits.
Recurrences & the Master Theorem
Grow the recursion tree of a divide-and-conquer recurrence level by level in 3D, add up the work on each level, and see which of the three cases of the master theorem you are in, and why.
Max Flow (Ford–Fulkerson)
Push as much flow as possible from a source to a sink through pipes of limited capacity. Watch augmenting paths, residual edges that undo flow, and the minimum cut that proves the answer is optimal.
Strongly Connected Components (Kosaraju)
Find the groups of vertices in a directed graph that can all reach each other. Watch Kosaraju's algorithm run a DFS, stack the vertices by finish time, reverse every edge and peel off one component per DFS.
Job Sequencing with Deadlines
Unit-time jobs, each with a profit and a deadline, and one machine. Watch the greedy algorithm take the most profitable jobs first and slot each into the latest free time before its deadline.
Convex Hull (Graham Scan)
Snap a rubber band around a set of points. Watch the Graham scan sort the points by angle, test every turn with a cross product, and pop the points that would make a dent, in O(n log n).
About Design & Analysis of Algorithms
An algorithm is a recipe, and the clearest way to understand one is to watch it work. Sort your own numbers with bubble, insertion, merge, quick and heap sort; trace BFS, DFS, Dijkstra, Prim, Kruskal and Floyd–Warshall on 3D graphs; and fill the dynamic-programming tables for knapsack and LCS cell by cell. Edit distance and activity selection show dynamic programming and greedy choices side by side. Grow a recursion tree to solve recurrences with the master theorem, push flow through a network with Ford–Fulkerson, find strongly connected components with Kosaraju, schedule jobs before their deadlines, and wrap a convex hull around points with the Graham scan. Each lesson explains the idea, its time complexity and when to use it.