Found 546 Articles for Algorithms

Babylonian method to find the square root

Chandu yadav
Updated on 17-Jun-2020 09:20:17

3K+ Views

The Babylonian method to find square root is based on one of the numerical method, which is based on the Newton- Raphson method for solving non-linear equations.The idea is simple, starting from an arbitrary value of x, and y as 1, we can simply get next approximation of root by finding the average of x and y. Then the y value will be updated with  number / x.Input and OutputInput: A number: 65 Output: The square root of 65 is: 8.06226AlgorithmsqRoot(number)Input: The number in real.Output: Square root of given number.Begin    x := number    y := 1    precision ... Read More

DFA based division

Samual Sam
Updated on 17-Jun-2020 09:23:06

205 Views

Deterministic Finite Automaton(DFA) is used to check whether a number is divisible by another number k or not. If it is not divisible, then this algorithm will also find the remainder.For the DFA based division, at first, we have to find the transition table of the DFA, using that table, we can easily find the answer. In the DFA, each state has only two transition 0 and 1.Input and OutputInput: The number: 50 and the divisor 3 Output: 50 is not divisible by 3 and remainder is: 2AlgorithmdfaDivision(num, k)Input: A number num, and divisor k.Output: Check divisibility and the remainder.Begin   ... Read More

Find GCD of two numbers

Monica Mona
Updated on 17-Jun-2020 08:18:25

1K+ Views

In mathematics, Greatest Common Divisor (GCD) is the largest possible integer, that divides both of the integers. The condition is that the numbers must be non-zero.We will follow the Euclidean Algorithm to find the GCD of two numbers.Input and OutputInput: Two numbers 51 and 34 Output: The GCD is: 17AlgorithmfindGCD(a, b)Input: Two numbers a and b.Output: GCD of a and b.Begin    if a = 0 OR b = 0, then       return 0    if a = b, then       return b    if a > b, then       return findGCD(a-b, b)   ... Read More

Find LCM of two numbers

Samual Sam
Updated on 17-Jun-2020 08:19:33

520 Views

In mathematics Least Common Multiple (LCM) is the smallest possible integer, that is divisible by both numbers.LCM can be calculated by many methods, like factorization, etc. but in this algorithm, we have multiplied the bigger number with 1, 2, 3…. n until we find a number which is divisible by the second number.Input and OutputInput: Two numbers: 6 and 9 Output: The LCM is: 18AlgorithmLCMofTwo(a, b)Input: Two numbers a and b, considered a > b.Output: LCM of a and b.Begin    lcm := a    i := 2    while lcm mod b ≠ 0, do       lcm := ... Read More

Decimal to Binary conversion

George John
Updated on 17-Jun-2020 08:24:51

801 Views

A decimal number can also be converted into its binary form. To convert a decimal number to binary number, we need to divide the number by 2 until it reaches 0 or 1. And in each step, the remainder are stored separately to form the binary equivalent number in reverse order.In this algorithm, we will follow the recursive approach. It will help us to solve the problem without using stack data structure. In the implementation, we know that recursion of a function will follow the internal stack. We will serve our job by using that stack.Input and OutputInput: Decimal number ... Read More

Lucky Numbers

karthikeya Boyini
Updated on 17-Jun-2020 08:23:49

2K+ Views

Lucky numbers are some special integer numbers. From basic numbers, some special numbers are eliminated by their position. Instead of their value, for their position, the numbers are eliminated. The numbers which are not deleted, they are the lucky numbers.The number deletion follows some rule. At first, every second number are deleted, after that, all 3rd numbers are deleted and so on.Here is some example −1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 (1 – 25 all) 1 3 5 7 9 11 ... Read More

Lagrange Interpolation

Ankith Reddy
Updated on 17-Jun-2020 08:34:36

831 Views

For constructing new data points within a range of a discrete set of given data point, the interpolation technique is used. Lagrange interpolation technique is one of them. When the given data points are not evenly distributed, we can use this interpolation method to find the solution. For the Lagrange interpolation, we have to follow this equation.Input and OutputInput: List of x and f(x) values. find f(3.25) x: {0, 1, 2, 3, 4, 5, 6} f(x): {0, 1, 8, 27, 64, 125, 216} Output: Result after Lagrange interpolation f(3.25) = 34.3281AlgorithmlargrangeInterpolation(x: array, fx: array, x1)Input − x array and fx ... Read More

Runge-Kutta 4th order rule for differential equation

Samual Sam
Updated on 17-Jun-2020 08:37:44

2K+ Views

Runge Kutta method is used for solving ordinary differential equations (ODE). It uses dy/dx function for x and y, and also need the initial value of y, i.e. y(0). It finds the approximate value of y for given x. For solving ODE, we have to follow these formulas:Here h is the height of the interval.Note: From these formulas, we can use first two k1 and k2 find the Runge-Kutta 2nd Order solution for ODE.Input and OutputInput: The x0 and f(x0): 0 and 0 the value of x = 0.4 the value of h = 0.1 Output: Answer of differential equation: ... Read More

Linear Regression

George John
Updated on 17-Jun-2020 08:47:12

753 Views

From a given set of data points, the linear regression finds an equation of straight line. The given points will follow the straight line. Using this formula, we can predict what will be the value for some other specific point, which is not present in the set currently.For solving linear regression problems using some data points, we have to follow these formulae:Here the m and c are the slope and the y-intercept respectively. Using these expressions, we can get the equation of straight line in this form: 𝑦 = 𝑚𝑥 + 𝑐.Input and OutputInput: The (x, y) coordinates of some ... Read More

Simpson's 1/3 Rule for definite integral

karthikeya Boyini
Updated on 17-Jun-2020 08:45:38

749 Views

Like the Trapezoidal Rule, Simpson’s 1/3rd rule is also used to find the integral value from the range a to b. The main difference between trapezoidal and the Simpson’s 1/3rd rule is, in the trapezoidal rule, the whole sections are divided into some trapezoids, but in this case, each trapezoid are also divided into two parts.For this rule, we will follow this formula:Here h is the width of the interval, and n is the number of intervals. We can find the h by using Input and OutputInput: The function f(x): (x+(1/x). The lower and upper limit: 1, 2. The number of ... Read More

Advertisements