Iterative Algorithms

Last updated on September 4th, 2023 at 09:48 pm

Here, We will learn about the iterative algorithm, iteration, implementation and properties of iteration.

Iterative Algorithms:

An Iterative Algorithm that calls repeatedly but for a finite number of times.

It use constructs like loops and sometime other data structures like stacks and queues to solve the problems.

Iteration is a technique in which function call repeatedly for a finite number of times.

iterative algorithm, iteration, example of iterative algorithm, example of iteration, properties of iteration,
Iterative approach to find key among items in the box.

Implementation

public static long fib (long n)
{
    if ((n == 1) || (n == 2)){
        return 1;
    }
    else{
        long prev = 1, current = 1, next = 0;
        for (long i=3; i<=n; i++){
            next = prev + current;
            prev = current;
            current = next;
         }
        return next;
    }
}

Properties of Iteration

  1. Iteration uses repetition structure.
  2. It terminates when the loop condition fails.
  3. It does not use the stack so it’s faster than recursion.
  4. It consumes less memory.
  5. Infinite looping uses CPU cycles repeatedly.
  6. It makes code longer.


Want to Contribute:-

If you like “To The Innovation” and want to contribute, you can mail your articles to 📧 contribute@totheinnovation.com. See your articles on the main page and help other coders.😎

Scroll to Top