Found 206 Articles for Dynamic Programming

Optimal Binary Search Tree

karthikeya Boyini
Updated on 17-Jun-2020 07:32:27

5K+ Views

A set of integers are given in the sorted order and another array freq to frequency count. Our task is to create a binary search tree with those data to find the minimum cost for all searches.An auxiliary array cost[n, n] is created to solve and store the solution of subproblems. Cost matrix will hold the data to solve the problem in a bottom-up manner.Input and OutputInput: The key values as node and the frequency. Keys = {10, 12, 20} Frequency = {34, 8, 50} Output: The minimum cost is 142. These are possible BST from the given values. For ... Read More

Break Number Into 3 parts to find max sum

Samual Sam
Updated on 17-Jun-2020 07:33:43

406 Views

A number is given. Our task is to break the number three times by n/2, n/3, and n/4 and find maximum sum we can make by dividing the number into three parts.For an example, 50 can be divided into {25, 16, 12}, now break each of the set {25, 16, 12}, into three divisions again, and so on. After completing the division up to 3 times, we will calculate the sum to find the maximum of them.This program can be solved in a recursive way, but in the recursive approach, we need to find the same results for multiple times, ... Read More

Mobile Numeric Keypad Problem

Arjun Thakur
Updated on 17-Jun-2020 07:31:04

948 Views

In this problem, a Numeric mobile keypad is given. We can only press top, bottom, right and left buttons of the current button, diagonal keys are not Allowed. We also cannot press the * and # buttons in the keypad.A digit is given, we have to find the number of possible numbers of given digits can be formed, using the keypad, maintaining given rules.Input and OutputInput: Digit count. Say 3 digit numbers. Output: Number of possible 3 digit numbers, that can be formed with the given conditions. Here the answer is 138.AlgorithmgetCount(n)Input: number of digits n.Output: Possible ways to type n ... Read More

Minimum number of squares whose sum equals to given number n

Ankith Reddy
Updated on 17-Jun-2020 07:42:14

339 Views

Any numbers can be represented by the sum of some perfect square numbers. In this problem, we need to find that how many minimum numbers of perfect square terms are needed to represent the given value.let the value is 94, so 95 = 92 + 32 + 22 + 12. so the answer will be 4The idea is to start from 1, we move further to get perfect squared numbers. When the value is 1 to 3, they must be formed with only 1s.Input and OutputInput: An integer number. Say 63. Output: Number of squared terms. Here the answer is ... Read More

Minimum Number of Jumps Problem

karthikeya Boyini
Updated on 17-Jun-2020 07:43:14

696 Views

In this problem, a list of positive integers is given. Each integer is denoting that how many maximum steps that can be made from the current element. Starting from the first element, we have to find the minimum number of jumps to reach the end item of the list.For the dynamic programming approach, a jumps array is defined to store the minimum number of jumps required. Like for a value of jumps[i], it indicates that how many minimum jumps are needed to reach the ith index of the array from the 0th index.Input and OutputInput: A list of integers. {1, ... Read More

Minimum number of coins that make a given value

Arjun Thakur
Updated on 17-Jun-2020 07:44:20

2K+ Views

There is a list of coin C(c1, c2, ……Cn) is given and a value V is also given. Now the problem is to use the minimum number of coins to make the chance V.Note: Assume there is the infinite number of coins C.In this problem, we will consider a set of different coins C{1, 2, 5, 10} are given, There is the infinite number of coins of each type. To make change the requested value we will try to take the minimum number of coins of any type. As an example, for value 22: we will choose {10, 10, 2}, ... Read More

Minimum Initial Points to Reach Destination

Samual Sam
Updated on 17-Jun-2020 06:54:13

742 Views

To start from the top-left corner of a given grid, one has to reach the bottom-right corner. Each cell in the grid contains a number, the number may positive or negative. When the person reaches a cell (i, j) the number of tokens he has, may be increased or decreased along with the values of that cell. We have to find the minimum number of initial tokens are required to complete the journey.There are some rules −We can either move to the right or to the bottom.We cannot move to a cell (i, j) if our total token is less ... Read More

Minimum Cost Polygon Triangulation

Samual Sam
Updated on 17-Jun-2020 06:56:14

545 Views

When nonintersecting diagonals are forming a triangle in a polygon, it is called the triangulation. Our task is to find a minimum cost of triangulation.The cost of triangulation is the sum of the weights of its component triangles. We can find the weight of each triangle by adding their sides, in other words, the weight is the perimeter of the triangle.Input and OutputInput: The points of a polygon. {(0, 0), (1, 0), (2, 1), (1, 2), (0, 2)} Output: The total cost of the triangulation. Here the cost of the triangulation is 15.3006.AlgorithmminCost(polygon, n)Here cost() will be used to calculate ... Read More

Min Cost Path

Chandu yadav
Updated on 17-Jun-2020 06:57:58

467 Views

A matrix of the different cost is given. Also, the destination cell is provided. We have to find minimum cost path to reach the destination cell from the starting cell (0, 0).Each cell of the matrix represents the cost to traverse through that cell. From a cell, we cannot move anywhere, we can move either to the right or to the bottom or to the lower right diagonal cell, to reach the destination.Input and OutputInput: The cost matrix. And the destination point. In this case the destination point is (2, 2). 1 2 3 4 8 2 1 5 3 ... Read More

Maximum sum rectangle in a 2D matrix

karthikeya Boyini
Updated on 17-Jun-2020 07:02:10

1K+ Views

A matrix is given. We need to find a rectangle (sometimes square) matrix, whose sum is maximum.The idea behind this algorithm is to fix the left and right columns and try to find the sum of the element from the left column to right column for each row, and store it temporarily. We will try to find top and bottom row numbers. After getting the temporary array, we can apply the Kadane’s Algorithm to get maximum sum sub-array. With it, the total rectangle will be formed.Input and OutputInput: The matrix of integers.  1  2 -1 -4 -20 -8 -3  4 ... Read More

Advertisements