C++ Recursion Performance

Write a program that allows a user to compare the performance of a recursion based algorithm against to an iteration based (loop) algorithm. Your program will implement solution for two different problems using a recursive solution and an iterative solution for each problem. The first problem is to calculate a factorial of a number (presented in class). You will need to include two algorithms, a recursive version and an iterative version. The factorial function for a number n (n!) is: n! = n*(n-1)*(n-2)*…*3*2*1 or n! = n* (n – 1)! Forn > 0 n! = 1 if n = 0 For example the factorial of n equal 9 is: 362,880 (= 9*8*7*6*5*4*3*2*1) The second problem is to calculate a Fibonacci Series. Fibonacci series is a series of numbers that are found by adding the two preceding (previous) numbers. The Fibonacci series can be determine by: fib(n) = fib(n-1) + fib(n-2) fib(0) = 1 fib(1) = 1 For example the Fibonacci Series for n equal 9 is: 0,1,1,2,3,5,8,13,21 Your program will have a menu with five options as shown below: MENU OPTIONS 1 – Calculate and Display Factorial of a Number 2 – Calculate and Display Fibonacci Series of a Number 3 – Compare Performance for Factorial Implementations 4 – Compare Performance for Fibonacci Series Implementations 0 – EXIT Enter an option (O to exit): Requirements • The user should be able to enter a choice in the menu. Check for input type mismatch. If user selects option 1, the user should then enter the number (n) to calculate the factorial. Use the recursive method and calculate the factorial; as possible display the result from each recursive call until the final result is obtained. If user selects option 2, the user should then enter the number (n) to calculate the Fibonacci Series. Use the recursive method and calculate the Fibonacci Series; as possible display the result from each recursive call until the final result (series) is obtained. If user selects option 3, the user should then enter the number (n) to calculate the factorial. In this case, you will need to run the calculation using both methods, measure the time used to execute each method and display the resulting time (in seconds) for each method. You will not display the actual result. You may need to execute multiple times each calculation to obtain an execution time you can measure. If user selects option 4, the user should then enter the number (n) to calculate the Fibonacci Series. In this case, you will need to run the calculation using both methods, measure the time used to execute each method and display the resulting time (in seconds) for each method. You will not display the actual series. You may need to execute multiple times each calculation to obtain an execution time you can measure. You will need at least 5 functions, one for each of the following tasks: print header, factorial – recursive, factorial – iterative, Fibonacci Series – recursive and Fibonacci Series – iterative. You may need more. You will also need to ensure that the output for each menu option displays the required information listed above. For this assignment we will be using C++ 11, which allow us to support a long long (integer) data type and a more precise time measurement library. See the tutorial part of this assignment with instructions in how to configure Eclipse to use C++ 11. Long long int uses 64 bits to storage an integer value so we can calculate factorial value for larger numbers. The range for unsigned long long int is: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 As part of C++ 11 a new high precision clock library called chrono was included. Such library allows time measurement with precision as greater as microseconds. To measure the execution time of each implementation, you will use the chrono library functions. In addition, you may need to execute multiple times each calculation to obtain an execution time you can measure. For instance, you may need to calculate the result 10 to 1000 times. See the tutorial part of this assignment for a sample code used to measure execution time of a function using the chrono library. rn in as a single PDF file (IN THIS ORDER) 1. Screen 1/0 – cut and paste into a txt file into eclipse. You will need the following six output: a. Option 1 – select a number between 5 and 15 b. Option 2 – select a number between 10 and 25 C. Option 3 – select a number between 5 and 9 d. Option 3 – select a number between 10 and 15 e. Option 4 – select a number between 10 and 25 f. Option 4 – select a number between 30 and 50 2. Header file. 3. Listing of main.cpp 4. Listing of your functions in a separate file from main.cpp. Show transcribed image text Write a program that allows a user to compare the performance of a recursion based algorithm against to an iteration based (loop) algorithm. Your program will implement solution for two different problems using a recursive solution and an iterative solution for each problem. The first problem is to calculate a factorial of a number (presented in class). You will need to include two algorithms, a recursive version and an iterative version. The factorial function for a number n (n!) is: n! = n*(n-1)*(n-2)*…*3*2*1 or n! = n* (n – 1)! Forn > 0 n! = 1 if n = 0 For example the factorial of n equal 9 is: 362,880 (= 9*8*7*6*5*4*3*2*1) The second problem is to calculate a Fibonacci Series. Fibonacci series is a series of numbers that are found by adding the two preceding (previous) numbers. The Fibonacci series can be determine by: fib(n) = fib(n-1) + fib(n-2) fib(0) = 1 fib(1) = 1 For example the Fibonacci Series for n equal 9 is: 0,1,1,2,3,5,8,13,21 Your program will have a menu with five options as shown below: MENU OPTIONS 1 – Calculate and Display Factorial of a Number 2 – Calculate and Display Fibonacci Series of a Number 3 – Compare Performance for Factorial Implementations 4 – Compare Performance for Fibonacci Series Implementations 0 – EXIT Enter an option (O to exit):

Requirements • The user should be able to enter a choice in the menu. Check for input type mismatch. If user selects option 1, the user should then enter the number (n) to calculate the factorial. Use the recursive method and calculate the factorial; as possible display the result from each recursive call until the final result is obtained. If user selects option 2, the user should then enter the number (n) to calculate the Fibonacci Series. Use the recursive method and calculate the Fibonacci Series; as possible display the result from each recursive call until the final result (series) is obtained. If user selects option 3, the user should then enter the number (n) to calculate the factorial. In this case, you will need to run the calculation using both methods, measure the time used to execute each method and display the resulting time (in seconds) for each method. You will not display the actual result. You may need to execute multiple times each calculation to obtain an execution time you can measure. If user selects option 4, the user should then enter the number (n) to calculate the Fibonacci Series. In this case, you will need to run the calculation using both methods, measure the time used to execute each method and display the resulting time (in seconds) for each method. You will not display the actual series. You may need to execute multiple times each calculation to obtain an execution time you can measure. You will need at least 5 functions, one for each of the following tasks: print header, factorial – recursive, factorial – iterative, Fibonacci Series – recursive and Fibonacci Series – iterative. You may need more. You will also need to ensure that the output for each menu option displays the required information listed above. For this assignment we will be using C++ 11, which allow us to support a long long (integer) data type and a more precise time measurement library. See the tutorial part of this assignment with instructions in how to configure Eclipse to use C++ 11. Long long int uses 64 bits to storage an integer value so we can calculate factorial value for larger numbers. The range for unsigned long long int is: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

As part of C++ 11 a new high precision clock library called chrono was included. Such library allows time measurement with precision as greater as microseconds. To measure the execution time of each implementation, you will use the chrono library functions. In addition, you may need to execute multiple times each calculation to obtain an execution time you can measure. For instance, you may need to calculate the result 10 to 1000 times. See the tutorial part of this assignment for a sample code used to measure execution time of a function using the chrono library. rn in as a single PDF file (IN THIS ORDER) 1. Screen 1/0 – cut and paste into a txt file into eclipse. You will need the following six output: a. Option 1 – select a number between 5 and 15 b. Option 2 – select a number between 10 and 25 C. Option 3 – select a number between 5 and 9 d. Option 3 – select a number between 10 and 15 e. Option 4 – select a number between 10 and 25 f. Option 4 – select a number between 30 and 50 2. Header file. 3. Listing of main.cpp 4. Listing of your functions in a separate file from main.cpp.

## Expert Answer

Answer to Write a program that allows a user to compare the performance of a recursion based algorithm against to an iteration bas…