FlashKeepers

Computer Science · College · College and University

Algorithms: Dynamic Programming

Overlapping subproblems, memoization versus tabulation, knapsack, LCS, edit distance, coin change and DP on grids and intervals.

About this set

40 basic cards for College Computer Science. Set 2 of 5 in Algorithms. It opens with "What is dynamic programming?" and "Define overlapping subproblems in DP". Study it alongside the other College sets below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What is dynamic programming?
Show answerAn algorithmic technique that solves optimization problems by breaking them into overlapping subproblems, storing solutions to avoid redundant computation.
Define overlapping subproblems in DP.
Show answerA problem exhibits overlapping subproblems when the same subproblems are solved multiple times in a naive recursive approach.
Define optimal substructure.
Show answerA problem has optimal substructure if an optimal solution can be constructed from optimal solutions to its subproblems.
What is memoization?
Show answerA top-down DP approach that uses recursion and stores results of subproblems to avoid recomputation.
How does memoization work algorithmically?
Show answerCall the recursive function, check if the result is cached before computing, cache the result, and return it.
What is tabulation?
Show answerA bottom-up DP approach that builds a table iteratively starting from base cases and computing larger subproblems using smaller ones.
How does tabulation work algorithmically?
Show answerInitialize a table with base cases, then iteratively fill the table using a recurrence relation until reaching the final answer.
Memoization vs tabulation: which uses less auxiliary space in typical problems?
Show answerTabulation often uses less space because it overwrites old values, while memoization must keep the entire recursion call stack.
Memoization vs tabulation: which is typically easier to implement?
Show answerMemoization is easier because you write the recursive logic directly and add caching, while tabulation requires careful loop ordering.
When is memoization preferable to tabulation?
Show answerWhen you only need to compute a subset of subproblems, or when the problem state space is sparse or hard to iterate in order.
When is tabulation preferable to memoization?
Show answerWhen you must solve all subproblems, want to avoid call stack overhead, or need guaranteed iteration order and control.
Define the 0/1 Knapsack problem.
Show answerGiven a knapsack of capacity W and n items with weights and values, select items to maximize value without exceeding capacity, using each item at most once.
What are the base cases for 0/1 Knapsack DP?
Show answerIf capacity is 0 or there are no items remaining, the maximum value is 0.
What is the recurrence relation for 0/1 Knapsack?
Show answerdp[i][w] = max(dp[i-1][w], dp[i-1][w-weight[i]] + value[i]) if weight[i] <= w, else dp[i-1][w].
What is the time complexity of 0/1 Knapsack?
Show answerO(n*W) where n is the number of items and W is the knapsack capacity.

25 more cards in the app

Study this set free