🌍 Data Structures & Algorithms · flashcards

Data Structures & Algorithms Algorithmic Paradigms Flashcards

52 question-and-answer cards covering Algorithmic Paradigms as it is examined in Data Structures & Algorithms. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.

52Cards in deck
24Free preview
16Syllabus topics
~173Chars per answer
FreePrice

24 sample cards from the Algorithmic Paradigms deck

Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.

  1. 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.

  2. 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.

  3. 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)$.

  4. 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)$.

  5. 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}$.

  6. 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)$.

  7. 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).

  8. 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.

  9. 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.

  10. 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).

  11. 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.

  12. 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}|)$.

  13. 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).

  14. 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])$.

  15. 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.

  16. 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})$.

  17. 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.

  18. 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.

  19. Give three classic problems solved by backtracking.

    The N-Queens problem, generating all permutations/subsets, and constraint puzzles such as Sudoku and graph coloring.

  20. 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.

  21. 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.

  22. 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.

  23. 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.

  24. 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.

What this deck covers

The Algorithmic Paradigms deck follows the Data Structures & Algorithms Algorithmic Paradigms syllabus — 5 chapters and 16 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 10.4 cards per chapter.

Answers are written to be recallable, not just readable — averaging about 173 characters, which is long enough to carry the reasoning and short enough to say out loud.

A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.

Algorithmic Paradigms flashcards FAQ

How many Algorithmic Paradigms flashcards are in this Data Structures & Algorithms deck?

52 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.

Are these Data Structures & Algorithms flashcards free?

Yes. The preview here is free to read with no signup, and the full 52-card deck is free inside the Examius app.

What do the Algorithmic Paradigms cards cover?

They follow the Data Structures & Algorithms Algorithmic Paradigms syllabus — 5 chapters and 16 topics — so the questions track what is actually examinable.

How should I use these flashcards?

Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.