{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}


Chapter17solutions - Chapter 17 17.1 a b c d e f 17.2 Not...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 17 17.1 a) 9 b) n-1 c) 15 d) 2 n -1 e) 177 f) number of calls for Fib(n)= (Fib(n-1) + Fib(n-2) + 1) 17.2 Not necessarily. A recursive function can have multiple recursive call sites (such as Movedisk, BinarySearch, or Fibonacci), each which will have its own return address. Recursive functions with one call site are likely to have only one return point. 17.3 The number would print in the reverse 17.4 count(20) returns 11. 17.5 a.1) The result is 0. a.2) The result is 2. a.3) The result is 0. b) Power(a, b) = Floor(log b a) c) -- frame pointer retaddr to Power 1 7 frame pointer retaddr to Power 0 11 7 17.6 a) int Sigma(int k) { return (k*(k+1)/2); } b) Assuming each activation record requires 5 16-bit slots (10 bytes), place 102 activation records on the run-time stack before we exhaust the stack memory. This means we can call Sigma(101) (including main) but Sigma(102) will not work.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
17.7 a) The activation record for SevenUp occupies 4 slots (8 bytes). With 16Kbytes allocated to the stack, the largest input value that will work is 2048 (assuming the activation record of main is inconsequential).
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}