Answered step by step
Verified Expert Solution
Question
1 Approved Answer
0 1 - Graded Participation Your participation score for this module is based on posting an answer to one of the practice questions below to
Graded Participation
Your participation score for this module is based on posting an answer to one of the practice questions below to this discussion
board. You can expect to spend an hour or more coming up with an answer to each practice question.
Review the information on the Graded Participation Information for more details and the Discussion Board Tips for details on
using Canvas discussion boards. Make sure to read the posting code to Canvas guide to make your answer look nice on the
discussion board!
Resist the temptation to just type in an answer. Make sure to try out your answer on hills!
Question
Implement a recursive reverseString in function like the one in the pdfs videos, but with a twist. You are no longer
allowed to print out the last character in s You are, however, allowed to print out the first character in s ie s
First, make one change to the function so that it prints out the first character in and then calls ReverseString on
minus the last character. Notice that it doesn't work anymore! It no longer reverses the string. Look at what it does and
think about why.
What further changes can you make to the function to fix it In other words, write a recursive function that reverses the
string, but you aren't allowed to print out the last character in s You are allowed print out the first character in s Useful
string functions:
@ ssize returns length of string s
ssubstrposlen returns the substring of of length len starting at postion pos zero is first position
Question
In the videospdfs you have seen a recursive solution for the fibonacci sequence and also an iterative solution. In this exercise
you will examine the runtime efficiency of both.
Enter the recursive solution from the videospdfs in a program. Add a simple main function which calls rabbit with a value
the user supplies. Try running the program with small values like and and make sure the results are correct.
Now, try the program with a larger value, like Notice approximately how long it takes for the program to run.
Now, do steps and with the iterative solution. Notice approximately how long it takes for the program to run.
In your reply to this discussion, post your main function, and indicate approximately how long it took your program to run for
the recursive approach and also for the iterative approach for the larger value
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started