Question

2. Consider the following functions. For each of them, determine how many times is ‘hey’ printed in terms of the input n. You should first write down a recurrence and then solve it using the recursion tree method. That means you should write down the first few levels of the recursion tree, specify the pattern, and then solve. (a) def fun(n) { if (n > 1) { print( ‘hi’ ‘hi’ ‘hi’ ) fun(n/4) fun(n/4) fun(n/4) }}

(b) def fun(n) { if (n > 1) { for i=1 to n { print( ‘hi’ ‘hi’ ) } fun(n/4) fun(n/4) fun(n/4) }}

2. Consider the following functions. For each of them, determine how many times is hey? printed in terms of the input n. You

(b) def fun(n) { if (n > 1) { for i=1 to n { print( hi hi ) fun (n/4) fun(n/4) fun(n/4)

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

I have attached four images for the question .First two are for part (a) and last two are for part(b) .I would suggest you to please comment your review for the answer.

Q2.

(a) Answer to 1st Part Of Question

2. (a) Resuvunce Relation is an follows: Tim / 3T12/4) + 1 m l otherwise Ruous Tree T(nu) in18) ng Tinig fin86) 7/1/16) (1116

Using lega(b) = log{ b) TM- 4( 3x log(a) - 1) . -* 413x (myy ) - ) T Usring log (6) = 1 oba) in <3 (m) ???. 1) TM) - L12007-(b) Answer to 2nd Part Of Question- 4m (1 - 13 og 4 (n)+1 T/m) f 31/014) + m inal ml [./16) Tin 116) TINI) Tim116) T116) 116) Tin (16) TH164) T(1/64) zact Tim)T(M 1= 40 (1.–134) 934[/+ Tlm) - um (1 – 636) (19logu mi) +(n)= 4m(! – (%) ( a ) ) Oraing boy.com - see Tim) = 4m (1-e 39 cm

Add a comment
Know the answer?
Add Answer to:
2. Consider the following functions. For each of them, determine how many times is ‘hey’ printed...
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
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