- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 546 Articles for Algorithms
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
739 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
538 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
466 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
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
374 Views
Maximum Sum Increasing subsequence is a subsequence of a given list of integers, whose sum is maximum and in the subsequence, all elements are sorted in increasing order.Let there is an array to store max sum increasing subsequence, such that L[i] is the max sum increasing subsequence, which is ending with array[i].Input and OutputInput: Sequence of integers. {3, 2, 6, 4, 5, 1} Output: Increasing subsequence whose sum is maximum. {3, 4, 5}.AlgorithmmaxSumSubSeq(array, n)Input: The sequence of numbers, number of elements.Output: Maximum sum of the increasing sub sequence.Begin define array of arrays named subSeqLen of size n. add ... Read More
310 Views
In a trading, one buyer buys and sells the shares, at morning and the evening respectively. If at most two transactions are allowed in a day. The second transaction can only start after the first one is completed. If stock prices are given, then find the maximum profit that the buyer can make.Input and OutputInput: A list of stock prices. {2, 30, 15, 10, 8, 25, 80} Output: Here the total profit is 100. As buying at price 2 and selling at price 30. so profit 28. Then buy at price 8 and sell it again at price 80. So ... Read More
214 Views
When a binary matrix is given, our task is to find a square matrix whose all elements are 1.For this problem, we will make an auxiliary size matrix, whose order is the same as the given matrix. This size matrix will help to represent, in each entry Size[i, j], is the size of a square matrix with all 1s. From that size matrix, we will get the maximum number to get the size of the biggest square matrix.Input and OutputInput: The binary matrix. 0 1 1 0 1 1 1 0 1 0 0 1 1 1 0 1 1 ... Read More
445 Views
There is a chain of pairs is given. In each pair, there are two integers and the first integer is always smaller, and the second one is greater, the same rule can also be applied for the chain construction. A pair (x, y) can be added after a pair (p, q), only if q < x.To solve this problem, at first, we have to sort given pairs in increasing order of the first element. After that, we will compare the second element of a pair, with the first element of the next pair.Input and OutputInput: A chain of number pairs. ... Read More
7K+ Views
If a chain of matrices is given, we have to find the minimum number of the correct sequence of matrices to multiply.We know that the matrix multiplication is associative, so four matrices ABCD, we can multiply A(BCD), (AB)(CD), (ABC)D, A(BC)D, in these sequences. Like these sequences, our task is to find which ordering is efficient to multiply.In the given input there is an array say arr, which contains arr[] = {1, 2, 3, 4}. It means the matrices are of the order (1 x 2), (2 x 3), (3 x 4).Input and OutputInput: The orders of the input matrices. {1, ... Read More
To Continue Learning Please Login
Login with Google