🌍 Data Structures & Algorithms · subject
Data Structures & Algorithms Algorithmic Paradigms Syllabus
The Algorithmic Paradigms syllabus for Data Structures & Algorithms in full: 5 chapters and 16 topics, every one listed below, plus 52 Algorithmic Paradigms flashcards with answers.
Algorithmic Paradigms syllabus: all 5 chapters
Expand any chapter to see its topics and sub-topics.
-
Divide & Conquer
3 topics- Paradigm Overview
- Classic Problems
- Karatsuba Multiplication
-
Greedy Algorithms
3 topics- Greedy Choice Property
- Classic Greedy Problems
- Greedy vs Dynamic Programming
-
Dynamic Programming
5 topics- DP Fundamentals
- 1D DP Problems
- 2D DP Problems
- Knapsack Patterns
- DP on Trees and Graphs
-
Backtracking
3 topics- Backtracking Template
- Classic Problems
- Pruning Techniques
-
Branch & Bound
2 topics- Overview and State Space
- Travelling Salesman Problem
Data Structures & Algorithms Algorithmic Paradigms flashcards — 52 questions with answers
What is an algorithmic paradigm?
A general, reusable strategy or design method for solving classes of problems — e.g., divide and conquer, greedy, dynamic programming, and backtracking. It describes the high-level approach, not a specific algorithm.
Name the four core algorithmic paradigms covered in a typical DSA course.
Divide and conquer, greedy, dynamic programming, and backtracking (with branch and bound as a refinement of backtracking).
What are the three conceptual steps of the divide-and-conquer paradigm?
1) Divide the problem into smaller subproblems, 2) Conquer by solving the subproblems recursively, and 3) Combine the subproblem solutions into a solution for the original problem.
State the Master Theorem recurrence form and give its three cases.
For $T(n)=aT(n/b)+f(n)$ with $a\geq 1,\ b>1$, let $c=\log_b a$. Case 1: if $f(n)=O(n^{c-\epsilon})$ then $T(n)=\Theta(n^{c})$. Case 2: if $f(n)=\Theta(n^{c})$ then $T(n)=\Theta(n^{c}\log n)$. Case 3: if $f(n)=\Omega(n^{c+\epsilon})$ (with regularity) then $T(n)=\Theta(f(n))$.
Give three classic divide-and-conquer problems and their time complexities.
Merge sort $\Theta(n\log n)$, binary search $\Theta(\log n)$, and Karatsuba multiplication $\Theta(n^{\log_2 3})\approx\Theta(n^{1.585})$.
What recurrence does merge sort satisfy, and what does the Master Theorem give?
$T(n)=2T(n/2)+\Theta(n)$. Here $c=\log_2 2=1$ and $f(n)=\Theta(n)$, so Case 2 gives $T(n)=\Theta(n\log n)$.
What problem does Karatsuba's algorithm solve, and what is its key idea?
It multiplies two large $n$-digit integers using only 3 recursive multiplications of half-size numbers instead of 4, by algebraic rewriting — reducing the naive $\Theta(n^{2})$ cost.
Write the Karatsuba decomposition for $x=x_1 B + x_0$ and $y=y_1 B + y_0$.
$xy = x_1 y_1 B^{2} + \big[(x_1+x_0)(y_1+y_0) - x_1 y_1 - x_0 y_0\big]B + x_0 y_0$, where $B=10^{n/2}$ (or $2^{n/2}$). The middle term reuses the products $x_1y_1$ and $x_0y_0$.
What recurrence and complexity characterize Karatsuba multiplication?
$T(n)=3T(n/2)+\Theta(n)$, giving $T(n)=\Theta(n^{\log_2 3})\approx\Theta(n^{1.585})$ by Master Theorem Case 1.
Define a greedy algorithm.
An algorithm that builds a solution step by step, at each step making the choice that looks best locally (the greedy choice), never reconsidering previous choices, hoping this yields a globally optimal solution.
What is the greedy-choice property?
The property that a globally optimal solution can be reached by making a locally optimal (greedy) choice at each step — the first greedy choice can always be extended to some optimal solution.
What two ingredients must a problem have for a greedy algorithm to yield an optimal solution?
The greedy-choice property and optimal substructure (an optimal solution contains optimal solutions to subproblems).
How does the greedy-choice property differ from optimal substructure?
Greedy-choice property: a locally optimal choice leads to a global optimum without needing to solve subproblems first. Optimal substructure: optimal solutions are composed of optimal subsolutions. DP relies on optimal substructure but not the greedy-choice property.
For the activity-selection problem, what is the greedy rule that gives optimality?
Repeatedly select the activity with the earliest finishing time among those compatible with previously chosen activities. Sorting by finish time and greedily picking is optimal in $O(n\log n)$.
State the greedy strategy and complexity for Huffman coding.
Repeatedly merge the two lowest-frequency nodes into a new node whose frequency is their sum, building the tree bottom-up. Using a min-heap, it runs in $O(n\log n)$ and produces an optimal prefix code.
What greedy strategy solves the fractional knapsack problem, and why does it fail for 0/1 knapsack?
Sort items by value-to-weight ratio $\frac{v_i}{w_i}$ (descending) and take as much of each as fits, taking fractions of the last. It fails for 0/1 knapsack because items cannot be split, so a locally best ratio choice may not lead to the global optimum.
Which greedy algorithms find minimum spanning trees, and what greedy choice does each make?
Kruskal's algorithm picks the smallest-weight edge that does not form a cycle; Prim's algorithm grows a tree by repeatedly adding the smallest-weight edge crossing the cut from the tree to the rest.
What greedy shortest-path algorithm requires non-negative edge weights, and what invariant does it maintain?
Dijkstra's algorithm. It greedily extracts the unvisited vertex with the smallest tentative distance and finalizes it, maintaining that finalized vertices have their true shortest distances.
Compare greedy and dynamic programming: how do they treat local choices?
Greedy makes one irrevocable locally optimal choice per step and never revisits it. Dynamic programming explores all choices at each subproblem, storing and combining subproblem solutions to guarantee global optimality.
When is greedy preferable to DP, given both may apply?
When the greedy-choice property holds, greedy is preferable because it is simpler and usually faster (often $O(n\log n)$) and uses less memory, whereas DP explores more states and typically needs more time and space.
Show the other 32 Algorithmic Paradigms flashcards
Give an example where greedy fails but DP succeeds, in the context of coin change.
For coin denominations $\{1,3,4\}$ making 6, greedy gives $4+1+1=3$ coins, but DP finds the optimum $3+3=2$ coins. Greedy is not optimal for arbitrary denominations.
Define dynamic programming.
A technique that solves problems by breaking them into overlapping subproblems, solving each subproblem once, and storing its result (memoization or tabulation) to avoid recomputation, exploiting optimal substructure.
What two properties must a problem have for dynamic programming to apply?
Optimal substructure (an optimal solution is built from optimal subsolutions) and overlapping subproblems (the same subproblems recur many times).
Contrast top-down memoization with bottom-up tabulation.
Top-down (memoization): recursion computes subproblems on demand and caches results. Bottom-up (tabulation): iteratively fills a table from base cases upward. Tabulation avoids recursion overhead; memoization only computes needed states.
How do you estimate the time complexity of a DP algorithm?
Time $\approx$ (number of distinct states) $\times$ (work per state / transition cost). For example, a 2D table with $O(1)$ transitions is $O(mn)$.
State the recurrence and complexity for the DP solution to the Fibonacci sequence.
$F(n)=F(n-1)+F(n-2)$ with $F(0)=0,\ F(1)=1$. With memoization or tabulation it is $O(n)$ time and can be $O(1)$ space, versus $O(\phi^{n})$ for naive recursion.
Give the DP recurrence for the maximum subarray sum (Kadane's algorithm).
$dp[i]=\max(a_i,\ dp[i-1]+a_i)$, and the answer is $\max_i dp[i]$. It runs in $O(n)$ time and $O(1)$ space.
State the DP recurrence for climbing stairs (1 or 2 steps at a time).
$dp[i]=dp[i-1]+dp[i-2]$ with $dp[0]=1,\ dp[1]=1$. The number of ways equals the Fibonacci-like count, $O(n)$ time.
What is the DP recurrence for the House Robber problem (no two adjacent)?
$dp[i]=\max\big(dp[i-1],\ dp[i-2]+a_i\big)$, choosing to skip or rob house $i$. It is $O(n)$ time, $O(1)$ space.
State the DP recurrence for the Longest Increasing Subsequence (LIS) in $O(n^{2})$.
$dp[i]=1+\max\{dp[j]:j<i,\ a_j<a_i\}$ (or $1$ if none), with answer $\max_i dp[i]$. An $O(n\log n)$ patience-sorting variant also exists.
Give the DP recurrence for edit distance (Levenshtein) between strings $A$ and $B$.
$dp[i][j]=dp[i-1][j-1]$ if $A_i=B_j$; otherwise $dp[i][j]=1+\min(dp[i-1][j],\ dp[i][j-1],\ dp[i-1][j-1])$, for delete, insert, and replace. Complexity $O(mn)$.
State the DP recurrence for the Longest Common Subsequence (LCS) of $A$ and $B$.
$dp[i][j]=dp[i-1][j-1]+1$ if $A_i=B_j$; otherwise $dp[i][j]=\max(dp[i-1][j],\ dp[i][j-1])$. Time and space $O(mn)$.
Give the DP recurrence for counting unique paths in an $m\times n$ grid (moves right/down).
$dp[i][j]=dp[i-1][j]+dp[i][j-1]$ with base cases $dp[0][j]=dp[i][0]=1$. Closed form: $\binom{m+n-2}{m-1}$.
State the recurrence for minimum path sum in a grid with cost $c_{i,j}$.
$dp[i][j]=c_{i,j}+\min(dp[i-1][j],\ dp[i][j-1])$, with the top-left as the base case. Complexity $O(mn)$.
What is the DP recurrence for the 0/1 knapsack problem?
$dp[i][w]=\max\big(dp[i-1][w],\ dp[i-1][w-w_i]+v_i\big)$ when $w_i\leq w$, else $dp[i][w]=dp[i-1][w]$. Complexity $O(nW)$ (pseudo-polynomial).
Why is 0/1 knapsack called pseudo-polynomial rather than polynomial?
Its $O(nW)$ running time depends on the numeric value $W$ (capacity), which requires $\log W$ bits to encode, so it is exponential in the input size in bits, not truly polynomial.
How does the unbounded knapsack recurrence differ from 0/1 knapsack?
Items may be reused, so the transition references the same item row: $dp[w]=\max(dp[w],\ dp[w-w_i]+v_i)$, iterating capacity in increasing order so each item can be taken multiple times.
In a 1D-array 0/1 knapsack implementation, why must the capacity loop run in decreasing order?
Iterating $w$ from high to low ensures each item is used at most once; ascending order would allow the same item to be counted multiple times (turning it into unbounded knapsack).
State the DP for the subset-sum / partition-equal-subset problem.
Boolean DP: $dp[s]$ = whether sum $s$ is achievable. Transition $dp[s] = dp[s]\ \lor\ dp[s-a_i]$ (capacity descending). For equal partition, target $= \frac{1}{2}\sum a_i$ and total must be even.
Give the DP recurrence for the coin-change minimum-coins problem.
$dp[a]=\min_{c\in\text{coins},\ c\leq a}\big(dp[a-c]+1\big)$ with $dp[0]=0$ and $dp[a]=\infty$ if unreachable. Complexity $O(a\cdot|\text{coins}|)$.
What is the general recurrence pattern for DP on trees using a post-order traversal?
Compute each node's DP value from its children's values after they are solved: $dp[u]=f\big(\{dp[v]:v\in\text{children}(u)\}\big)$. A common form keeps two states per node (included / excluded).
State the tree DP for maximum independent set (weighted, no two adjacent nodes) on a rooted tree.
For each node $u$: $incl[u]=w_u+\sum_{v\in child(u)} excl[v]$ and $excl[u]=\sum_{v\in child(u)}\max(incl[v],\ excl[v])$. Answer $=\max(incl[root],\ excl[root])$.
How is DP applied to shortest paths in a DAG?
Process vertices in topological order; for each vertex relax outgoing edges: $dist[v]=\min(dist[v],\ dist[u]+w(u,v))$. This gives $O(V+E)$ single-source shortest paths on a DAG, even with negative weights.
What DP algorithm computes all-pairs shortest paths, and what is its recurrence?
Floyd–Warshall: $dp^{(k)}[i][j]=\min\big(dp^{(k-1)}[i][j],\ dp^{(k-1)}[i][k]+dp^{(k-1)}[k][j]\big)$, iterating $k$ over all intermediate vertices. Complexity $O(V^{3})$.
Define backtracking as an algorithmic paradigm.
A systematic, depth-first search that incrementally builds candidate solutions and abandons (backtracks from) a candidate as soon as it determines the candidate cannot be extended to a valid complete solution.
Write the general backtracking template in pseudocode.
backtrack(state): if state is a complete solution -> record it; else for each choice in candidates(state): if valid(choice): apply(choice); backtrack(state); undo(choice). The undo step restores state after exploring a branch.
Give three classic problems solved by backtracking.
The N-Queens problem, generating all permutations/subsets, and constraint puzzles such as Sudoku and graph coloring.
What is pruning in backtracking, and why is it important?
Pruning discards branches of the search tree that cannot lead to a valid or optimal solution (via constraint checks or bounds), drastically reducing explored states and turning exponential search into a practical one.
Distinguish constraint-based pruning from bounding (branch and bound).
Constraint-based pruning cuts branches that violate feasibility (e.g., two queens attacking). Bounding (branch and bound) computes an optimistic bound on a partial solution's objective and prunes branches that cannot beat the best solution found so far.
What is the state space of a search problem, and how does branch and bound explore it?
The state space is the tree/graph of all partial and complete configurations reachable by sequential choices. Branch and bound explores it by branching into subproblems and using bounds to prune non-promising nodes, often with a best-first (priority-queue) order.
Define the Travelling Salesman Problem (TSP) and its optimal-tour objective.
Given $n$ cities and pairwise distances $d(i,j)$, find a minimum-cost Hamiltonian cycle visiting each city exactly once and returning to the start, minimizing $\sum_{k} d(\pi_k,\pi_{k+1})$. TSP is NP-hard.
What is the Held–Karp dynamic programming complexity for exact TSP, and how does it compare to brute force?
Held–Karp runs in $O(n^{2}2^{n})$ time and $O(n\,2^{n})$ space, a major improvement over brute-force enumeration of all $(n-1)!$ tours, though still exponential.
Data Structures & Algorithms Algorithmic Paradigms FAQ
What is in the Data Structures & Algorithms Algorithmic Paradigms syllabus?
Data Structures & Algorithms Algorithmic Paradigms is split into 5 chapters: Divide & Conquer, Greedy Algorithms, Dynamic Programming, Backtracking and Branch & Bound. Together they contain 16 topics.
How many chapters are in Data Structures & Algorithms Algorithmic Paradigms?
5 chapters, containing 16 topics. The largest chapter is Dynamic Programming, with 5 topics.
Are there flashcards for Data Structures & Algorithms Algorithmic Paradigms?
Yes — a 52-card Algorithmic Paradigms deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.