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. (Make sure to use your own words – do not cut and paste someone else's solution.)

Solutions

Expert Solution

Following is the code for Tower of Hanoi problem being solved by recursion:

class Main {
  
static void tower(int n, char first,
               char second, char third)
{
   if (0 == n)
   return;

   tower(n - 1, first, third,
                       second);

   System.out.printf("Move the disk %d from %c to %c\n",
                       n, first, second);

   tower(n - 1, third, second, first);
}

public static void main(String[] args)
{
   tower(3, 'F', 'S', 'T');
}
}

If we write this program logic in a relation form, it will written as :

T(n)= 2*T(n-1)+1

When we apply Back Substitution method on this relation we get T(n)=((2^(n+1))-1) and hence the complexity is exponential O(2^n).

Please find the attached screenshot of the output of the program:


Related Solutions

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.
____ 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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT