Found 546 Articles for Algorithms

Trapezoidal Rule for definite integral

Samual Sam
Updated on 17-Jun-2020 08:48:56

1K+ Views

Definite integrals can be solved using this trapezoidal rule. To integrate a function f(x) between the range a to b is basically finding the area below the curve from point x = a to x = b. To find that area, we can divide the area into n trapezoids, and the width of each trapezoid is h, so we can say that (b - a) = nh. When the number of trapezoids increases, the result of area calculation will be more accurate. To solve integrals, we will follow this formula.Here h is the width of the interval, and n is the ... Read More

Secant method to solve non-linear equation

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

956 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

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

657 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

Vertex cover Problem

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

1K+ Views

For an undirected graph, the vertex cover is a subset of the vertices, where for every edge (u, v) of the graph either u or v is in the set.Using a binary tree, we can easily solve the vertex cover problem.This problem can be divided into two sub-problems. When the root is part of the vertex cover. For this case, the root covers all children edges. We can simply find the size of vertex cover for left and right sub-tree, and add 1 for the root.Input and OutputInput: A binary tree. Output: The vertex cover is 3.  AlgorithmvertexCover(root node)In this ... Read More

Shortest Common Super Sequence

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

166 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

Advertisements