Coin Change: Minimum number of coins

Problem: You are given n types of coin denominations of values v(1)<v(2)<…<v(n) (all integers). Assume v(1)=1, so you can always make change for any amount of money C. Give an algorithm which makes change for an amount of money C with as few coins as possible. #include <stdio.h> #include <stdlib.h> int main() { int i,n,den[20],temp[20],min,min_idx, … Read more

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

This question already has answers here: Closed 9 years ago. Possible Duplicate: 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 dynamic programming looks the same and at others memoization & dynamic programming look … Read more

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 that I couldn’t answer and I can’t think of an efficient algorithm and it’s bugging me. I feel like … Read more

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: Algorithm complexity to be of O(N^3) History: With the help of the Algorithmist, Larry and a modification of Kadane’s Algorithm, i managed to solve … Read more

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 Another example, as the string could have more than one word. string1 = apple pie available string2 = apple pies answer = apple … Read more

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

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 6 years ago. Improve this question I am looking for a manageably understandable example for someone who wants to learn Dynamic Programming. There are nice … Read more

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 required to encode the input). Unfortunately I did not get it. Can anybody explain that pseudo-polynomial thing to me slowly … Read more