Introduction
A knapsack is a bag with straps, usually carried by soldiers to help them take their valuables or things which they might need during their journey. The 0/1 knapsack problem is a very famous interview problem. The problem statement is as follows:
Given a set of items, each of which is associated with some weight and value. Find the subset of items which can be carried into the knapsack with weight limit W. It is required that the cumulative value of the items in the knapsack is maximum value possible.
In simple words, it asks you to pick certain items from the set of items ...

Read More
# dynamic programming

## Find Interleaving Strings using Dynamic Programming

Introduction
This problem is already discussed in the post here. This post attempts to solve the same using the dynamic programming approach. Here is a brief description of the problem. Given three strings A, B and C such that A is "ab", B is "ade" and C is "adabe" find if C is an interleaving of A and B or not.
Interleaving means constructing the third string C using the characters of A and B such that the characters in A and B preserve their relative ordering in C. In the above example C is an interleaving of A and B.
Approach to Find Interleaving Strings using Dynamic Programming
How ...

Read More
## Dynamic Programming – CrazyNumbers

Problem Statement
We are interested in finding the count of all N digit crazy numbers. Let us define a crazy number. A crazy number is a number where the magnitude of its consecutive digits differ by 1.
For e.g.: Here is a list of all 2 digit crazy numbers:
The total number of 2 digit crazy numbers is 17. You can notice that in all the numbers the digits differ only by 1.
Similarly for three digit numbers the count reaches 32. For four digit numbers it becomes 61 and very soon it increases exponentially to 924903595810 for a 40 digit number.
It might look like the a problem wh...

Read More
## Dynamic Programming – Longest Palindromic Sequence

[nextpage title="Introduction"]
Palindromes are fascinating character sequences in a string. A palindrome is a string which reads the same when read from either of the ends. This post in particular talks about palindromic sub sequences.
To know more about a sub sequence, please check my post on Longest Common Sub sequence.
A palindromic sequence means a sequence of characters which is a palindrome. Now, we must understand it clearly that we are talking about a sub sequence and not a substring.
Understanding the Longest Palindromic Subsequence problem better
It is really easy to say if...

Read More
## Further Reading for Minimum Spanning Tree

Introduction
This is a supplement to the posts for Minimum Spanning Tree and their Analysis. Check out the other related articles in the following section.
Further Reading for Minimum Spanning Tree
This section is meant to be read in conjunction to the post Minimum Spanning Tree - Prim's Algorithm
The minimum spanning tree of a Graph is the union of minimum spanning trees of its connected components.
This is a very important observation and it must be discussed in length and breadth because this will help us design our algorithm for MST in a
better way.
Why is it so important to underst...

Read More
## Dynamic Programming – Minimum Number of Coins

[nextpage title="Introduction"]This is the third post in Dynamic Programming - Online Classes.
This is another article which demonstrates the usage of dynamic programming to solve a different problem in hand. To learn the basics of dynamic programming check my first article on dynamic programming.
Purpose of the post
The purpose of this article is to solve another problem using dynamic programming, this is a very famous interview question which is asked in multiple interviews. So without wasting any time, let us jump into the problem and ways to solve the same.
Find minimum number of coi...

Read More
## Dynamic Programming – Distinct Paths between two points

Introduction
This is the second post in Dynamic Programming - Online Classes.
This is another article which demonstrates the usage of dynamic programming to solve a different problem in hand. To learn the basics of dynamic programming check my first article on dynamic programming.
Purpose of the article
The purpose of this article is to solve another problem using dynamic programming, this is another very famous interview question which is asked in multiple interviews. So without wasting any time, let us jump into the problem and ways to solve the same.
Count the number of distinct path...

Read More