h6 - • Determine theoretically both the number of calls...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
[30] Homework 6. Programming Project The goal of this assignment is to understand recursive programs and analyze them. Run the following recursion (written in a pseudo-code) for n = 2, 2 3 , 2 9 , 2 81 , and 2 243 . function fun(n) if ( n 2) then return (1) else return (5 + fun( 3 n )) Your job is to: Implement the above function and have it print out the following (you should print these values each time you run your program for various values of n ): 1. Calls Count : The number of recursive calls to the above function (the initial call is counted). 2. Returned Value : The Fnal value returned by the function.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: • Determine theoretically both the number of calls and the value returned in terms of n . That is, construct two recurrence relations each describing one of these values for a general n . Use telescoping to solve these recurrence relations ( Hint : Let T ( n ) be the time complexity (frequency count) for the above algorithm and F ( n ) be the value returned by the function fun . Write a recurrence and then solve it.) • Compare printed values with the theoretical results in each case. 1...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online