02Chapter 2: The greedy paradigm and the greedy-choice propertyThis chapter assumes you know Big-O notation, how to sort and use a binary heap, and how to read short Python. It builds the working model you need before the later chapters that prove specific greedy algorithms correct.4 min read
03Chapter 3: Why a greedy choice is safe: the exchange argumentThis chapter assumes you know Big-O notation, can read short Python, and have seen the idea of a greedy algorithm: build a solution by repeatedly taking the choice that looks best right now. The question here is how to prove that such a choice never costs you the optimum.4 min read
04Chapter 4: Activity selection by earliest finish timeThis chapter assumes you know Big-O notation, can sort an array in O(n log n), and can read short Python. It also assumes you have met the idea of a greedy choice from the previous chapters.3 min read
05Chapter 5: Fractional knapsack by value-to-weight ratioThis chapter assumes you know Big-O notation, can sort a list in Python, and have read the previous chapters on the greedy-choice property and the exchange argument. It uses both ideas.4 min read
06Chapter 6: Job sequencing with deadlines and profitsThis chapter assumes you know the greedy-choice property and the exchange argument from the earlier chapters. It also assumes you can read Python and know basic array and union-find operations.4 min read
07Chapter 7: Huffman coding and optimal prefix codesThis chapter assumes you know binary trees, binary heaps (priority queues), and the greedy exchange argument from the earlier chapters. It builds the optimal prefix code for a set of symbol frequencies.4 min read
08Chapter 8: Dynamic programming: optimal substructure and overlapping subproblemsThis chapter assumes you know Big-O notation, can write and trace recursive functions, and can solve simple recurrences such as T(n) = T(n-1) + 1. The later chapters on knapsack, LCS, matrix chain and coin change all reuse the ideas introduced here.4 min read
09Chapter 9: Memoization and tabulation comparedThis chapter assumes you know what optimal substructure and overlapping subproblems mean, can read a recurrence, and are comfortable with Python recursion and lists. Both techniques here compute the same recurrence. They differ in the order they evaluate subproblems, the memory they use, and how the3 min read
11Chapter 11: Longest common subsequenceThis chapter assumes you know Big-O notation, basic recursion, and 2D arrays. It builds on the idea of optimal substructure and on tabulation from the previous chapters.4 min read
12Chapter 12: Edit distanceEdit distance measures how different two strings are by counting the fewest single-character changes that turn one into the other. This chapter assumes you know the recurrence and table-filling pattern from the longest common subsequence chapter, and that you can read Big-O notation and simple Pytho3 min read
13Chapter 13: Matrix chain multiplicationThis chapter assumes you know Big-O notation, can read Python, and have seen the 0/1 knapsack and LCS tables. The new idea here is that the subproblems are intervals of a sequence, not prefixes.3 min read
14Chapter 14: Coin change: counting ways and minimum coinsThis chapter assumes you know the 0/1 knapsack recurrence, the difference between memoization and tabulation, and Big-O notation. Coin change is an unbounded knapsack: each coin value may be used any number of times. It comes in two forms that look alike but need different loop structures. You will 3 min read
15Chapter 15: Representing graphs: adjacency list versus matrixThis chapter assumes you know basic graph terms (vertex, edge, directed, weighted, degree), Big-O notation, and Python lists. Every later algorithm in this tutorial, including BFS, Kruskal, Dijkstra and Floyd-Warshall, runs on one of the two representations below. Its stated running time depends on 4 min read
16Chapter 16: BFS and DFS: traversal order, edge types, and complexityThis chapter assumes you know graph terminology (vertices, edges, directed, connected), how queues and stacks work, and Big-O notation. It also assumes you can read short Python. Graphs are stored as adjacency lists, as in the previous chapter, so graph[u] is the list of neighbours of u.3 min read
17Chapter 17: Topological sort of a DAGA topological sort lists the vertices of a directed graph so that every edge points forward in the list. This chapter assumes you know BFS and DFS, the adjacency-list representation, and DFS edge types (tree, back, forward, cross). GATE questions on this topic ask for a valid order, the number of va4 min read
18Chapter 18: Union-find with union by rank and path compressionThis chapter assumes you know Big-O notation, arrays, and basic graph terms such as vertices, edges, and connected components. It also assumes you can read short Python. Kruskal's algorithm in the next chapters depends on this structure.4 min read
19Chapter 19: Spanning trees and the cut propertyThis chapter assumes you know basic graph terms (vertices, edges, weights, connectivity), how greedy proofs work, and how to read short Python. It builds the theory that Kruskal's and Prim's algorithms rely on. The next chapter covers the algorithms themselves.4 min read
20Chapter 20: Kruskal's and Prim's algorithmsThis chapter assumes you know the cut property from the previous chapter, union-find with union by rank and path compression, and binary heaps. Both algorithms build a minimum spanning tree (MST) of a connected, weighted, undirected graph. Both are greedy, and the cut property justifies both.4 min read
21Chapter 21: Single-source shortest paths and relaxationThis chapter assumes you know basic graph terms (directed, weighted, path), Big-O notation, and the idea of a priority queue. It sets up the vocabulary and the one operation, relaxation, that Dijkstra, Bellman-Ford, and the DAG algorithm all use. The three algorithms differ only in the order in whic4 min read
22Chapter 22: Dijkstra's algorithm and why it fails with negative edgesThis chapter assumes you know binary heaps (insert and extract-min in O(log n)) and adjacency lists. It also assumes you know edge relaxation, covered in the previous chapter: if dist[u] + w < dist[v], set dist[v] = dist[u] + w.4 min read
23Chapter 23: Bellman-Ford and negative cycle detectionThis chapter assumes you know edge relaxation from the previous chapter, Dijkstra's algorithm, and Big-O notation. Dijkstra fails when an edge weight is negative. Bellman-Ford handles negative edges. It also reports when a negative cycle makes shortest paths undefined.3 min read
24Chapter 24: Floyd-Warshall all-pairs shortest pathsThis chapter assumes you know adjacency matrices, edge relaxation, and the basic dynamic programming idea of building a table from smaller subproblems. Dijkstra and Bellman-Ford answer "how far is everything from one source?". Floyd-Warshall answers "how far is every vertex from every other vertex?"4 min read
25Chapter 25: Choosing between greedy and dynamic programming in GATE questionsThis chapter assumes you know the greedy-choice property, optimal substructure, overlapping subproblems, and the exchange argument from earlier chapters. It also assumes you can read Python. Here we turn those ideas into a fast decision procedure for exam questions.3 min read