Answered step by step
Verified Expert Solution
Link Copied!

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

01- 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 1
Implement a recursive reverseString in C++ function like the one in the pdf's 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, i.e. s[0].
First, make one change to the function so that it prints out the first character in s,s[0] and then calls ReverseString on s
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:
@ s.size()- returns length of string s
s.substr(pos,len)- returns the substring of s of length len starting at postion pos (zero is first position)
Question 2
In the videos/pdfs, 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 videos/pdfs 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 5 and 6 and make sure the results are correct.
Now, try the program with a larger value, like 45. Notice approximately how long it takes for the program to run.
Now, do steps 1 and 2 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 45.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions