Question

In: Computer Science

Iterative implementation of a recursive algorithm executes faster than recursive implementation because no _____ needs to...

Iterative implementation of a recursive algorithm executes faster than recursive implementation because no _____ needs to be maintained.

Select one:

a. recursion

b. iteration

c. recurrence

d. stack

e. array

Solutions

Expert Solution

Definitions:

Recursion: A function calling itself is called as Recursion

Example: consider a function fun as below

fun(n)

{

if(n<0)

return 0;

else

return fun(n-1)+1;

}

for, suppose user invokes fun(4) then

fun(4) calls fun(3)

fun(3) calls fun(2)

fun(2) calls fun(1)

fun(1) calls fun(0)

the result returned value will be 4

Iteration: A set of instructions executing repeatedly

Example: consider the following loop

c=0;

for(i=0;i<4;i++)

{

c=c+1;

}

here, for loop runs for i=0,1,2,3

and the result we get c=4

Answer: no stack needs be maintained for iteration.

Explanation: Observe the given example for Recursion above, there given function fun(n) calling fun(n-1) if n<0

Here, a stack is maintained to store different values of function fun with various parameters of n

For suppose, see the below case

if fun(n) is invoked by user and n>0 then add fun(n) to the top of the stack

if fun(n) calls fun(n-1) and n>0 then add fun(n) to the top of the stack

if fun(n-1) calls fun(n-2)and n>0 then add fun(n-1) to the top of the stack

this process of adding contents to stack occurs until function stops calling itself.

if a function stops calling itself then remove the element in the top of the stack.

if the stack is empty that means Recursion task is completed

Here, stack is used to trace the sequence of function calling in Recursion.

Iteration do not contain calling functions itself so iteration do not need stack

so maintaining stack is a time taking process to the Recursion. So Iteration is faster than Recursion

If you have any doubts feel free to ask me in comments

Have a nice day.!!


Related Solutions

What is the difference between recursive and iterative bubble sort? I thought that iterative is most...
What is the difference between recursive and iterative bubble sort? I thought that iterative is most effecient but is that only with large data sets? If recursive scans through less each time, does that mean its always more effecient?
A systems analyst tests a new algorithm designed to work faster than the currently-used algorithm. Each...
A systems analyst tests a new algorithm designed to work faster than the currently-used algorithm. Each algorithm is applied to a group of 52 sample problems. The new algorithm completes the sample problems with a mean time of 16.34 hours. The current algorithm completes the sample problems with a mean time of 16.93 hours. The standard deviation is found to be 3.913 hours for the new algorithm, and 3.6243.624 hours for the current algorithm. Conduct a hypothesis test at the...
A systems analyst tests a new algorithm designed to work faster than the currently-used algorithm. Each...
A systems analyst tests a new algorithm designed to work faster than the currently-used algorithm. Each algorithm is applied to a group of 41sample problems. The new algorithm completes the sample problems with a mean time of 23.42 hours. The current algorithm completes the sample problems with a mean time of 26.39 hours. Assume the population standard deviation for the new algorithm is 3.442 hours, while the current algorithm has a population standard deviation of 5.364 hours. Conduct a hypothesis...
A systems analyst tests a new algorithm designed to work faster than the currently-used algorithm. Each...
A systems analyst tests a new algorithm designed to work faster than the currently-used algorithm. Each algorithm is applied to a group of 5454 sample problems. The new algorithm completes the sample problems with a mean time of 11.9011.90 hours. The current algorithm completes the sample problems with a mean time of 14.0714.07 hours. Assume the population standard deviation for the new algorithm is 5.1155.115 hours, while the current algorithm has a population standard deviation of 5.7365.736 hours. Conduct a...
A systems analyst tests a new algorithm designed to work faster than the currently-used algorithm. Each...
A systems analyst tests a new algorithm designed to work faster than the currently-used algorithm. Each algorithm is applied to a group of 51 51 sample problems. The new algorithm completes the sample problems with a mean time of 24.43 24.43 hours. The current algorithm completes the sample problems with a mean time of 24.68 24.68 hours. The standard deviation is found to be 3.481 3.481 hours for the new algorithm, and 3.420 3.420 hours for the current algorithm. Conduct...
A systems analyst tests a new algorithm designed to work faster than the currently-used algorithm. Each...
A systems analyst tests a new algorithm designed to work faster than the currently-used algorithm. Each algorithm is applied to a group of 60 sample problems. The new algorithm completes the sample problems with a mean time of 22.16 hours. The current algorithm completes the sample problems with a mean time of 24.18 hours. Assume the population standard deviation for the new algorithm is 5.572 hours, while the current algorithm has a population standard deviation of 4.365 hours. Conduct a...
015824 A systems analyst tests a new algorithm designed to work faster than the currently-used algorithm....
015824 A systems analyst tests a new algorithm designed to work faster than the currently-used algorithm. Each algorithm is applied to a group of 89 sample problems. The new algorithm completes the sample problems with a mean time of 17.64 hours. The current algorithm completes the sample problems with a mean time of 17.75 hours. Assume the population standard deviation for the new algorithm is 4.561 hours, while the current algorithm has a population standard deviation of 4.210 hours. Conduct...
Problem 5: writing a faster implementation For this homework assignment, you will write a faster implementation...
Problem 5: writing a faster implementation For this homework assignment, you will write a faster implementation of do_insertions_simple (which we will call do_insertions_fast). We won't need anything extra (no special modules, no advanced algorithms, no Numpy) in order to obtain a considerable speedup. Let's think about what makes do_insertions_simple slow, and about how we can rewrite the whole thing in a faster way. The biggest problem with do_insertions_simple is that it calls insert once for every element of the insertions...
C++ This needs to be a recursive combinational array please. This NEEDS to be recursive and...
C++ This needs to be a recursive combinational array please. This NEEDS to be recursive and no vectors. Thank you Write a program that solves the knapsack problem recursively for an arbitrary knapsack capacity and series of weights. Assume the weights are sorted in an array. Hint: The arguments to the knapsack function are target weight and the array index where the remaining items start. The knapsack problem in its simplest form involves trying to fit items of different weights...
Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort I need it in Java with...
Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort I need it in Java with comments and I need the input file to be placed with Scanner not BufferedReader Please help I need Class River Class CTRiver and Class Driver Class River describes river’s name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong() that returns true if river is above 30 miles...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT