Question

In: Computer Science

Recursion is a technique for breaking down a complex problem into smaller pieces and then combining...

Recursion is a technique for breaking down a complex problem into smaller pieces and then combining the results to obtain the desired answer. The most common example of recursion is calculating factorials. Describe another problem that can be solved using recursion and outline the approach using Java or Pseudo-Code. Discuss the Big-Oh run time performance of your example.

Solutions

Expert Solution

Here, I am using a Pseudo Code for Fibonacci function:-

int fib(int n) {

if(n <= 1) {

// base case

return 1;

} else {

// recursive case

return fib(n – 1) + fib(n – 2);

}

}

When computing big-O, we can make the following simplifications:

1. Eliminate any term whose contribution to the total is insignificant as N becomes large

o(n2+n) = o(n2) for large n

2. Eliminate any constant factors

o(3n) = o(n) for large n

The stragegy for computing Big-O depends on whether or not your program is recursive. For the case of iterative solutions, we try and count the number of executions that are performed. For the case of recursive solutions, we first try and compute the number of recursive calls that are performed.

Before going to solve the Big Oh, We must understand this concept:-

Gauss Summation:-

In many situations you have a case where you have a code block which executes 1 time, then 2 times, then 3 times until n times. In order to calculate the Big-O for code that follows this format we use the solution for the sum of an arithmetic series.

1 + 2 + 3 + . . . + (N - 2) + (N - 1) + N

= (N · (N + 1)) / 2

= (1 / 2) N2 + (1 / 2) N

Which is

O( N2 )

If we ask a question on the mid term where you need to compute the Big O of a recursive function it will be of the form where you simply need to calculate the number of calls in the recursion call tree. Often the number of calls is big O(bd ) where b is the branching factor (worst case number of recursive calls for one execution of the function) and d is the depth of the tree (the longest path from the top of the tree to a base case).

Here is the call tree of Fib(5);

The branching factor is 2. The depth is n where n is the number on which the function is called. Thus the big O of this function is:

O( bd ) = O( 2n )


Related Solutions

____ is the process of breaking up a big goal into smaller more manageable pieces so they can be communicated, assigned and measured.
________________ is the process of breaking up a big goal into smaller more manageable pieces so they can be communicated, assigned and measured.A. inventory managementB. cashflow managementC. personnel managementD. project management
Recursion is a programming technique in which a function calls itself. This project applies recursion to a new problem, and illustrates the recursive implementation of backtracking.
RECURSIVELY FINDING PATHS THROUGH A MAZE in C++INTRODUCTIONRecursion is a programming technique in which a function calls itself. This project applies recursion to a new problem, and illustrates the recursive implementation of backtracking.DESCRIPTIONConsider finding all paths from an entrance on the top of a maze to an exit on the bottom. This task can be accomplished recursively, so in this project, you design, implement, test, and document a program that calls a recursive function to find a path through a maze.An...
Assume that you are breaking a stick into 3 pieces by uniformly and independently selecting two...
Assume that you are breaking a stick into 3 pieces by uniformly and independently selecting two break points ? and ?. If we denote the event that these pieces form a triangle by T and lengths of the three pieces by ?, ? and ?, calculate: a. ?(? ∩ (? < ? < ?)), b. The probability that the pieces form an equilateral triangle.
The ability to achieve more pain relief by combining smaller amounts of codeine with aspirin is...
The ability to achieve more pain relief by combining smaller amounts of codeine with aspirin is an example of a(n) Question 13 options: 1) Additive interaction 2) Antagonistic interaction 3) Potentiative interaction 4) Adverse interaction
A random sample of n=9 pieces of Manila rope has a mean breaking strength of 82500...
A random sample of n=9 pieces of Manila rope has a mean breaking strength of 82500 pounds and a standart deviation of 3154 pounds. Assuming that it is reasonable to treat these data as a sample from a normal population, what can we assert with 95% confidence about the maximum error if µ =82500 pounds is used as an estimate of the mean breaking strength of such rope? And construct a %98 confidence interval for the mean breaking strenght of...
A composition of n is made by breaking n down into summands. For example, the compositions...
A composition of n is made by breaking n down into summands. For example, the compositions of 3 are {3}. {2 + 1}, {1 + 2}, {1 + 1 + 1}. In general, there are 2^(n-1) compositions of n. Prove that there are 3^(n-1) double compositions of n.
Problem 9.41 A firecracker in a coconut blows the coconut into three pieces. Two pieces of...
Problem 9.41 A firecracker in a coconut blows the coconut into three pieces. Two pieces of equal mass fly off south and west, perpendicular to each other, at 20 m/s . The third piece has twice the mass as the other two. Part A What is the speed of the third piece? Express your answer using two significant figures. Part B What is the direction of the third piece? Give the direction as an angle east of north. Express your...
Writing a thesis and breaking down Langston Hughes I too sing America
Writing a thesis and breaking down Langston Hughes I too sing America
Module 05 What is the definition of metabolism? The breaking down of body compounds is known...
Module 05 What is the definition of metabolism? The breaking down of body compounds is known as what? True or False: Amino acids becoming protein is an anabolic reaction. What is the sugar that helps make up ATP? From which B vitamin is CoA, or coenzyme A, derived? What are the features/characteristics of aerobic metabolism? For short, intense exercise, which energy-producing pathway does the body rely on most? Anaerobic means ________. When a person performing intense physical exercise begins to...
Cellular respiration is the process of breaking down organic molecules into usable energy for cellular processes....
Cellular respiration is the process of breaking down organic molecules into usable energy for cellular processes. Why isn’t glucose broken down in one step to make ATP? What is the equation for cellular respiration? What are the major steps in cellular respiration?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT