Question

PROBLEM 5 Consider the recursive C function below: void foo (unsigned int n) cout << tick <<endl; if(n > ) { foo (n-1); foo(n-1) 5A: Complete the following table indicating how many ticks are printed for various parameters n. Unenforceable rule: derive your answers by hand -- not simply by writing a program calling the function. number of ticks printed when foo(n) is called 4 5.B Derive a conjecture expressing the number of ticks as a i.e., complete the following: function of n -- Conjecture: for all n20, calling foo(n) results in being printed ticks 5.C: Prove your conjecture from part B (hint: Induction!)
For part 5B I already have 2^(n+1) -1, but I'm not sure how to prove it using induction. I am actually taking the prerequisite to this class concurrently and we haven't gotten to that part unfortunately so please show clear steps.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

For induction we have to prove a base case and then we give a induction hypotheses and then we prove for inductive step

Here we can see that base case will be n=0 which gives 2^1 -1 =1 hence its correct

Induction hypotheses: Let's assume that this is true for some k

Inductive step: we have to prove this for k+1

So for K number of times, it will be printed is 2^(k+1)-1

According to our step for f(k+1), the result should be 2^(k+2)-1

And for k+1 we have 2 more calls to f(k) hence two times the number of ticks printed by f(k) and another one which is printed in f(k+1) itself so the total number becomes f(k+1)= 2*f(k)+1 times of we know that for f(k) it is

2^(k+1)-1 putting this value gives us f(k+1)=2^(k+2)-1

Hence this is true for any k

Add a comment
Know the answer?
Add Answer to:
For part 5B I already have 2^(n+1) -1, but I'm not sure how to prove it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PROBLEM 4: Consider the recursive C++ function below: void foo(unsigned int n) {     if(n==0)        ...

    PROBLEM 4: Consider the recursive C++ function below: void foo(unsigned int n) {     if(n==0)         cout << "tick" << endl;     else {         foo(n-1);         foo(n-1);         foo(n-1);     } } 4.A: Complete the following table indicating how many “ticks” are printed for various parameters n. Unenforceable rule: derive your answers “by hand” -- not simply by writing a program calling the function. n number of ticks printed when foo(n) is called 0 1 2 3 4 4.B:...

  • Prove using mathematical induction that for every positive integer n, = 1/i(i+1) = n/n+1. 2) Suppose...

    Prove using mathematical induction that for every positive integer n, = 1/i(i+1) = n/n+1. 2) Suppose r is a real number other than 1. Prove using mathematical induction that for every nonnegative integer n, = 1-r^n+1/1-r. 3) Prove using mathematical induction that for every nonnegative integer n, 1 + i+i! = (n+1)!. 4) Prove using mathematical induction that for every integer n>4, n!>2^n. 5) Prove using mathematical induction that for every positive integer n, 7 + 5 + 3 +.......

  • Don't attempt if you can't attempt fully, i will dislike a nd negative comments would be...

    Don't attempt if you can't attempt fully, i will dislike a nd negative comments would be given Please it's a request. c++ We will read a CSV files of a data dump from the GoodReads 2 web site that contains information about user-rated books (e.g., book tit le, publication year, ISBN number, average reader rating, and cover image URL). The information will be stored and some simple statistics will be calculated. Additionally, for extra credit, the program will create an...

  • Don't attempt if you can't attempt fully, i will dislike and negative comments would be given...

    Don't attempt if you can't attempt fully, i will dislike and negative comments would be given Please it's a request. c++ We will read a CSV files of a data dump from the GoodReads 2 web site that contains information about user-rated books (e.g., book titnle, publication year, ISBN number, average reader rating, and cover image URL). The information will be stored and some simple statistics will be calculated. Additionally, for extra credit, the program will create an HTML web...

  • How to write the insert, search, and remove functions for this hash table program? I'm stuck......

    How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • C++ Programming Hi! Sorry for all the material attached. I simply need help in writing the...

    C++ Programming Hi! Sorry for all the material attached. I simply need help in writing the Facility.cpp file and the other files are included in case they're needed for understanding. I was able to complete the mayday.cpp file but am stuck on Facility. The following link contains a tar file with the files provided by the professor. Thank you so much in advanced! http://web.cs.ucdavis.edu/~fgygi/ecs40/homework/hw4/ Closer.h: #ifndef CLOSER_H #define CLOSER_H #include <string> #include "gcdistance.h" struct Closer { const double latitude, longitude;...

  • specifically on finite i pmu r the number of objøcts or ways. Leave your answers in fornsiala form, such as C(3, 2) nporkan?(2) Are repeats poasib Two points each imal digits will have at le...

    specifically on finite i pmu r the number of objøcts or ways. Leave your answers in fornsiala form, such as C(3, 2) nporkan?(2) Are repeats poasib Two points each imal digits will have at least one xpeated digin? I. This is the oounting problem Al ancmher so ask yourelr (1) ls onder ipo n How many strings of four bexadeci ) A Compuir Science indtructor has a stack of blue can this i For parts c, d. and e, suppose...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT