Unit summary

  • Dynamic programming solves overlapping sub-problems once and stores answers: Fibonacci in Θ(n), binomial coefficients in Θ(nk).
  • Floyd-Warshall gives all-pairs shortest paths in Θ(n³) by adding intermediate vertices one at a time.
  • 0/1 knapsack uses V[i][j] = max(V[i − 1][j], vᵢ + V[i − 1][j − wᵢ]) in Θ(nW).
  • BFS (queue) and DFS (stack) both take Θ(V + E); BFS gives unweighted shortest paths.
  • Connected components come from repeated traversals.
  • DFS on a directed graph finds cycles through back edges and gives a topological order of a DAG.

Glossary

Term Meaning
Back edge Edge to an ancestor in DFS.
BFS Breadth first search using a queue.
Binomial coefficient Number of ways to choose k of n.
Connected component Maximal connected set of vertices.
DAG Directed acyclic graph.
DFS Depth first search using a stack.
Dynamic programming Solving overlapping sub-problems once and storing results.
Floyd-Warshall All-pairs shortest path algorithm.
In-degree Number of incoming edges.
Memoization Top-down caching of results.
Pseudo-polynomial Polynomial in the numeric value of the input.
Tabulation Bottom-up filling of a table.
Topological sort Order respecting all edge directions.

Question bank

Short Answer Questions (2 marks each)

  1. What is dynamic programming?
  2. State Pascal's rule.
  3. Define memoization.
  4. What is the time complexity of Floyd-Warshall?
  5. State the recurrence of 0/1 knapsack.
  6. Which data structure does BFS use?
  7. What is a connected component?
  8. What is a back edge?
  9. Define a DAG.
  10. What is topological sorting?

Medium Answer Questions (5 marks each)

  1. Explain memoization and tabulation with Fibonacci.
  2. Compute C(6, 3) using dynamic programming.
  3. Explain the Floyd-Warshall algorithm.
  4. Solve a 0/1 knapsack instance with a table.
  5. Compare BFS and DFS.
  6. Explain topological sorting with an example.

Long Answer Questions (15 marks each)

  1. Explain dynamic programming and solve Fibonacci and binomial coefficients with it.
  2. Explain Floyd-Warshall with a worked example and analyse it.
  3. Explain the 0/1 knapsack algorithm with an example and the traceback.
  4. Explain BFS, DFS, connected components and topological sorting with analysis.

Sources

  • Official BCA syllabus Design and Analysis of Algorithms, course code 26BCA404DS03, Unit III