Efficient Computation of Fibonacci Numbers
Modify the application in Code Listing 16-18 by replacing the recursive method for computing Fibonacci terms with an iterative version and try to make it as efficient as possible. Modify the application so it outputs the elapsed time in both seconds and milliseconds. Finally, run the application and generate output showing the rime required to compute the terms of the sequence in positions 45, 46, 47, 48, 49, and 50. Comment on the results.
Want to see the full answer?
Check out a sample textbook solutionChapter 16 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
C Programming Language
C How to Program (8th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Database Concepts (8th Edition)
- MULTIPLE FUNCTIONS AND RECURSIVE FUNCTIONS Use #include<stdio.h> Implement the picture shown below.arrow_forwardMULTIPLE FUNCTIONS AND RECURSIVE FUNCTIONS Use #include<stdio.h> Implement the picture shown below.arrow_forwardNo plagarism! Correct and detailed answer ( code with comments and output screenshot if necessary)arrow_forward
- Problem: Recursive Power Method Design a python function that uses recursion to raise a number to a power. The function should accept two arguments: the number to be raised, and the exponent. Assume the exponent is a nonnegative integer. Write the main() function to input the required parameters as shown in thesample input/output. Sample Output:Average number of words per line: 26.0Enter a number: 2Enter a positive whole number between 1 and 100: 102.0 raised to the power of 10 is 1,024.00arrow_forwardWrite a recursive function that returns the smallest integer in an array. Write a test program that prompts the user to enter a list of five integers and displays the smallest integer.arrow_forwardWrite the definition of a recursive function int simpleSqrt(int n) The function returns the integer square root of n, meaning the biggest integer whose square is less than or equal to n. You may assume that the function is always called with a nonnegative value for n. Use the following algorithm: If n is 0 then return 0. Otherwise, call the function recursively with n-1 as the argument to get a number t. Check whether or not t+1 squared is strictly greater than n. Based on that test, return the correct result. For example, a call to simpleSqrt(8) would recursively call simpleSqrt(7) and get back 2 as the answer. Then we would square (2+1) = 3 to get 9. Since 9 is bigger than 8, we know that 3 is too big, so return 2 in this case. On the other hand a call to simpleSqrt(9) would recursively call simpleSqrt(8) and get back 2 as the answer. Again we would square (2+1) = 3 to get back 9. So 3 is the correct return value in this case.arrow_forward
- Write a recursive function that takes as a parameter a nonnegative integer and generates the following pattern of stars. If the nonnegative integer is 4, the pattern generated is as follows: **** *** ** * * ** *** **** Also, write a program that prompts the user to enter the number of lines in the pattern and uses the recursive function to generate the pattern. For example, specifying 4 as the number of lines generates the preceding pattern.arrow_forwardCreate a class Recursion. It will have two static methods: removeX and countSubstring and write each function recursively. Recursion class removeX The removeX function will take a String as a parameter. It will return a new String that is the same as the original String, but with all “x” characters removed. This method will be case insensitive. countSubstring The countSubstring function will take two strings as parameters and will return an integer that is the count of how many times the substring (the second parameter) appears in the first string without overlapping with itself. This method will be case insensitive. For example: countSubstring(“catwoman loves cats”, “cat”) would return 2 countSubstring(“aaa nice”, “aa”) would return 1 because “aa” only appears once without overlapping itself. Create a Main class to test and run your Recursion class.arrow_forwardCreate a function that returns the nth catalan number. In combinatorial mathematics, the Catalan numbers form a sequence of natural numbers that occur in various counting problems, often involving recursively-defined objects. They are named after the Belgian mathematician Eugène Charles Catalan (1814-1894). For more info, check out the resource tab. Examples getCatalanNumber (0) → 1 getCatalanNumber (6) → 132 getCatalanNumber (8) 1430 Notes Inputs are zero and positive integers.arrow_forward
- RECURSIVE FUNCTION use #inlcude<stdio.h> Implement the function shown in the picture below. Thank youuuu.arrow_forwardPlease solve All the questions properlyarrow_forwardWrite a recursive function that computes the sum of the digits in an integer. Use the following function header: def sumDigits(n):For example, sumDigits(234) returns Write a test program that prompts the user to enter an integer and displays its sum.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning