Found 547 Articles for Algorithms

Shortest Common Super Sequence

Chandu yadav
Updated on 17-Jun-2020 08:09:32

163 Views

Shortest common super-sequence is a sequence where each element of both of the given sequences is present. In other words, we can say that the given two strings, both are sub-sequence of Shortest Common Super-Sequence.When there are no common characters in two strings, then we can simply concatenate them to get Super-sequence. But when they have some common characters, then firstly we have to find the longest string, then add extra characters of the other string.Input and OutputInput: Two strings. “ABCDEF” and “XYDEF” Output: The length of the shortest common super-sequence. Here the super-sequence is “ABCDEFXY”. So the length is ... Read More

Rod Cutting

Samual Sam
Updated on 17-Jun-2020 08:11:06

4K+ Views

A rod is given of length n. Another table is also provided, which contains different size and price for each size. Determine the maximum price by cutting the rod and selling them in the market.To get the best price by making a cut at different positions and comparing the prices after cutting the rod.Let the f(n) will return the max possible price after cutting a row with length n. We can simply write the function f(n) like this.f(n) := maximum value from price[i]+f(n – i – 1), where i is in range 0 to (n – 1).Input and OutputInput:The price ... Read More

Partition problem

karthikeya Boyini
Updated on 17-Jun-2020 07:25:03

1K+ Views

For this problem, a given set can be partitioned in such a way, that sum of each subset is equal.At first, we have to find the sum of the given set. If it is even, then there is a chance to divide it into two sets. Otherwise, it cannot be divided.For even value of the sum, then we will create a table named partTable, now use the following condition to solve the problem.partTable[i, j] is true, when subset of array[0] to array[j-1] has sum equal to i, otherwise it is false.Input and OutputInput: A set of integers. {3, 1, 1, ... Read More

Palindrome Partitioning

George John
Updated on 17-Jun-2020 07:22:59

268 Views

In this algorithm, the input is a string, a partitioning of that string is palindrome partitioning when every substring of the partition is a palindrome.In this algorithm, we have to find the minimum cuts are needed to palindrome partitioning the given string.Input and OutputInput: A string. Say “ababbbabbababa” Output: Minimum cut to partition as palindrome. Here 3 cuts are needed. The palindromes are: a | babbbab | b | ababaAlgorithmminPalPart(str)Input: The given string.Output: Minimum number of palindromic partitioning from the string.Begin    n := length of str    define cut matrix and pal matrix each of order n x n ... Read More

Friend Pairing Problem

Ankith Reddy
Updated on 17-Jun-2020 07:29:15

484 Views

In a group, there is n number of friends. Each person can remain single or be paired with some other friend. Find the total number of ways, in which friends can remain single or can be paired up.If one pair has two friends’ p and q, then (p, q) or (q, p) are same. For a group of n friends, let f(n) be the number of ways how they can be paired up or remain single. Then either the nth person remains single, or paired up. If the nth person is single, then we recur for (n - 1) friends. If ... Read More

Wildcard Pattern Matching

Samual Sam
Updated on 17-Jun-2020 07:27:53

1K+ Views

For this problem, one main string and another wildcard patterns are given. In this algorithm, it will check whether the wildcard pattern is matching with the main text or not.The wildcard pattern may contain letters or ‘*’ or ‘?’ Symbols. The ‘?’ Is used to match a single character and ‘*’ is used to match the sequence of characters including empty space.When the character is ‘*’: We can ignore the star character and move to check next characters in the pattern.When the next character is ‘?’, then we can ignore only the current character in the text, and check for ... Read More

Optimal Binary Search Tree

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

4K+ 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

394 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

930 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

328 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

Advertisements