Explore BrainMass

Explore BrainMass

    Iterative and Recursive Algorithms

    Not what you're looking for? Search our solutions OR ask your own Custom question.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Solutions to some problems are intrinsically recursive, and writing them in an iterative fashion is difficult. The reverse also holds. Find an example or a recursive procedure and represent it as an iterative procedure. Also, choose an iterative procedure that you would re-write as recursive. What challenges did you face in the process? How did you go about resolving them?

    © BrainMass Inc. brainmass.com March 7, 2023, 3:34 am ad1c9bdddf

    Solution Preview


    An example of a recursive algorithm is computation of a power of 2.

    Using recursive algorithm, we have:
    power_2 (int n) //power_2 is a recursive function using the n, value of exponent, as argument.
    if n = 0 //if n is 0, it will return the value of 1
    return 1;

    Solution Summary

    This posting contains the answers to the given problems.