CSE331_HW3 - 2200 k P(k 4.5 A proof by mathematical...

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

View Full Document Right Arrow Icon
3.27 If the recursive routine in Section 2.4 used to compute Fibonacci numbers is run for N=50, is stack space likely to run out? Why or why not? long fib( int n) { if (n<=1) return 1; else return fib(n-1) + fib(n-2); } It is likely to run out of space because for this recursive routine because as N gets larger the running time and the amount of space used grows exponentially. If this was not a stack and was an array using a loop there would never be a space issue unless N was extremely large. So basically it boils down to how stack’s elements are accessed and the way this particular function is run especially since it is recursive. 4.4 A proof by mathematical induction that P(n) filled nodes -> P(n+1) null nodes is true for every positive integer n consists of 2 steps. 1. Basis step. Show that proposition P(1) is true. 1 N N 2. Inductive step. For every positive k, the implication P(k) P(k+1) is true. P(k) for every k is proved by inductive hypothesis . [P(1) 2200 k (P(k) P(k+1))]
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2200 k P(k) 4.5 A proof by mathematical induction that the maximum number of nodes in a binary tree of height P(h) = 2 h+1-1 is true for all positive integers h. 1. Basis step. Show that proposition P(1) is true. P(1) = 2 1+1-1 = 3. As the following tree shows, the height is one because the root is not including and there are 3 nodes. 1 N N 2. Inductive step. For every positive k, the implication P(k) → P(k+1) is true. P(k) = 2 k+1-1 <=> P(k+1) = 2 (k+1)+1-1 2 k+1-1 <=> 2 (k+1)+1-1 (2 k + 2) -1 <=> (2 k + 2 2 ) -1 2 k + 2 <=> 2 k + 4 2<=> 4 2 1 <=> 2 1+1 2 k <=> 2 (k+1) 4.6 A proof by mathematical induction that P(n) filled nodes -> P(n+1) null nodes is true for every positive integer n consists of 2 steps. 1. Basis step. Show that proposition P(1) is true. 1 N N 2. Inductive step. For every positive k, the implication P(k) → P(k+1) is true. P(k) for every k is proved by inductive hypothesis . [P(1) ∧ 2200 k (P(k) → P(k+1))] → 2200 k P(k)...
View Full Document

Page1 / 2

CSE331_HW3 - 2200 k P(k 4.5 A proof by mathematical...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online