Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [dynamic-programming]

Dynamic programming is an algorithmic technique for efficiently solving problems which have recursive structure with many overlapping subproblems. Do NOT use this tag for general "dynamic" behavior in code.

dynamic-programming
362 votes
12 answers
144k views

What is the difference between memoization and dynamic programming?

What is the difference between memoization and dynamic programming? I think dynamic programming is a subset of memoization. Is it right?
Sanghyun Lee's user avatar
  • 22.5k
291 votes
10 answers
146k views

What is dynamic programming? [closed]

What is dynamic programming? How is it different from recursion, memoization, etc? I have read the wikipedia article on it, but I still don't really understand it.
user avatar
275 votes
9 answers
223k views

What is the difference between bottom-up and top-down?

The bottom-up approach (to dynamic programming) consists in first looking at the "smaller" subproblems, and then solve the larger subproblems using the solution to the smaller problems. The top-down ...
Guest's user avatar
  • 3,167
234 votes
21 answers
203k views

How to determine the longest increasing subsequence using dynamic programming?

I have a set of integers. I want to find the longest increasing subsequence of that set using dynamic programming.
Tony's user avatar
  • 2,493
218 votes
10 answers
140k views

Difference between Divide and Conquer Algo and Dynamic Programming

What is the difference between Divide and Conquer Algorithms and Dynamic Programming Algorithms? How are the two terms different? I do not understand the difference between them. Please take a simple ...
saplingPro's user avatar
  • 21.2k
151 votes
8 answers
16k views

Throwing cats out of windows

Imagine you're in a tall building with a cat. The cat can survive a fall out of a low story window, but will die if thrown from a high floor. How can you figure out the longest drop that the cat can ...
AndrewF's user avatar
  • 6,962
118 votes
6 answers
51k views

Why is the knapsack problem pseudo-polynomial?

I know that Knapsack is NP-complete while it can be solved by DP. They say that the DP solution is pseudo-polynomial, since it is exponential in the "length of input" (i.e. the numbers of bits ...
Michael's user avatar
  • 41.8k
115 votes
20 answers
185k views

Find common substring between two strings

I'd like to compare 2 strings and keep the matched, splitting off where the comparison fails. So if I have 2 strings: string1 = "apples" string2 = "appleses" answer = "apples&...
NorthSide's user avatar
  • 1,479
97 votes
5 answers
93k views

A simple example for someone who wants to understand Dynamic Programming [closed]

I am looking for a manageably understandable example for someone who wants to learn Dynamic Programming. There are nice answers here about what is dynamic programming. The fibonacci sequence is a ...
Khaled Alshaya's user avatar
84 votes
4 answers
14k views

What is the minimum cost to connect all the islands?

There is a grid of size N x M. Some cells are islands denoted by '0' and the others are water. Each water cell has a number on it denoting the cost of a bridge made on that cell. You have to find the ...
vaibhavatul47's user avatar
75 votes
5 answers
77k views

What's the difference between recursion, memoization & dynamic programming? [duplicate]

Related question: Dynamic programming and memoization: top-down vs bottom-up approaches I have gone through a lot of articles on this but can't seem to make sense of it. At times recursion and ...
Sakibul Alam's user avatar
  • 1,791
65 votes
9 answers
31k views

Find the number of occurrences of a subsequence in a string

For example, let the string be the first 10 digits of pi, 3141592653, and the subsequence be 123. Note that the sequence occurs twice: 3141592653 1 2 3 1 2 3 This was an interview question ...
Jake's user avatar
  • 651
65 votes
11 answers
74k views

Getting the submatrix with maximum sum?

Input: A 2-dimensional array NxN - Matrix - with positive and negative elements.Output: A submatrix of any size such that its summation is the maximum among all possible submatrices. Requirement: ...
guirgis's user avatar
  • 1,133
63 votes
4 answers
23k views

Is there a generic way to memoize in Scala?

I wanted to memoize this: def fib(n: Int) = if(n <= 1) 1 else fib(n-1) + fib(n-2) println(fib(100)) // times out So I wrote this and this surprisingly compiles and works (I am surprised because ...
pathikrit's user avatar
  • 33.5k
60 votes
1 answer
18k views

How to count integers between large A and B with a certain property?

In programming contests, the following pattern occurs in a lot of tasks: Given numbers A and B that are huge (maybe 20 decimal digits or more), determine the number of integers X with A ≤ X ≤ B ...
Niklas B.'s user avatar
  • 94.5k

15 30 50 per page
1
2 3 4 5
380