Found 510 Articles for Algorithms

Secant method to solve non-linear equation

Chandu yadav
Updated on 17-Jun-2020 08:55:00

1K+ Views

Secant method is also used to solve non-linear equations. This method is similar to the Newton-Raphson method, but here we do not need to find the differentiation of the function f(x). Only using f(x), we can find f’(x) numerically by using Newton’s Divide difference formula. From the Newton-Raphson formula, we know that, Now, using divide difference formula, we get, By replacing the f’(x) of Newton-Raphson formula by the new f’(x), we can find the secant formula to solve non-linear equations.Note: For this method, we need any two initial guess to start finding the root of non-linear equations.Input and OutputInput: The ... Read More

Evaluate Postfix Expression

karthikeya Boyini
Updated on 17-Jun-2020 07:45:37

7K+ Views

For solving a mathematical expression, we need prefix or postfix form. After converting infix to postfix, we need postfix evaluation algorithm to find the correct answer.Here also we have to use the stack data structure to solve the postfix expressions.From the postfix expression, when some operands are found, pushed them in the stack. When some operator is found, two items are popped from the stack and the operation is performed in correct sequence. After that, the result is also pushed in the stack for future use. After completing the whole expression, the final result is also stored in the stack ... Read More

Convert Infix to Postfix Expression

Arjun Thakur
Updated on 02-Sep-2023 01:50:33

70K+ Views

Infix expressions are readable and solvable by humans. We can easily distinguish the order of operators, and also can use the parenthesis to solve that part first during solving mathematical expressions. The computer cannot differentiate the operators and parenthesis easily, that’s why postfix conversion is needed.To convert infix expression to postfix expression, we will use the stack data structure. By scanning the infix expression from left to right, when we will get any operand, simply add them to the postfix form, and for the operator and parenthesis, add them in the stack maintaining the precedence of them.Note: Here we will ... Read More

Convert Infix to Prefix Expression

Samual Sam
Updated on 17-Jun-2020 07:51:44

5K+ Views

To solve expressions by the computer, we can either convert it in postfix form or to the prefix form. Here we will see how infix expressions are converted to prefix form.At first infix expression is reversed. Note that for reversing the opening and closing parenthesis will also be reversed.for an example: The expression: A + B * (C - D)after reversing the expression will be: ) D – C ( * B + Aso we need to convert opening parenthesis to closing parenthesis and vice versa.After reversing, the expression is converted to postfix form by using infix to postfix algorithm. ... Read More

Word Wrap Problem

karthikeya Boyini
Updated on 17-Jun-2020 07:54:57

1K+ Views

A sequence of words is given, there is a limit on the number of characters for each line. By putting line breaks, in such a way that lines are printed clearly.The lines must be balanced, when some lines have lots of extra spaces and some lines are containing a small number of extra spaces, it will balance them to separate lines. It tries to use the same number of extra spaces to make them balanced.This algorithm will produce how many words can be placed in one line, and how many lines are needed.Input and OutputInput: The length of words for ... Read More

Weighted Job Scheduling

Ankith Reddy
Updated on 17-Jun-2020 07:53:36

707 Views

A list of different jobs is given, with the starting time, the ending time and profit of that job are also provided for those jobs. Our task is to find a subset of jobs, where the profit is maximum and no jobs are overlapping each other.In this algorithm, we use a table to store the results of sub-problems and using the results of subproblems, the whole problem can be solved in a bottom-up manner.The time complexity of this algorithm is O(n^2), but we can change it to O(n Log n) by using a binary search method to search con-conflicting jobs.Input ... Read More

Ugly Numbers

George John
Updated on 17-Jun-2020 08:04:29

3K+ Views

Ugly numbers are those number whose prime factors are 2, 3 or 5. From 1 to 15, there are 11 ugly numbers 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15. The numbers 7, 11, 13 are not ugly because they are prime. The number 14 is not ugly because in its prime factor the 7 will come.In this program, we will try to find the nth ugly number.Input and OutputInput: Take the term number. Say it is 10 Output: The 10th ugly number is 12AlgorithmgetUglyNumbers(n)Input: The number of terms.Output: Find nth Ugly numbers.Begin    define array named ... Read More

Shortest Common Super Sequence

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

176 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

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

Advertisements