Explore BrainMass
Share

Iterative and Recursive Algorithms

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 21, 2019, 7:14 pm ad1c9bdddf
https://brainmass.com/computer-science/algorithms/iterative-and-recursive-algorithms-284883

Solution Preview

Hi,

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.

$2.19