225_13_heap - Let T(n) be the number of times the statement...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Let T(n) be the number of times the statement current= current.next; is executed reading in a list of size n. Is this a valid proof that T(n)= (n-1)(n-2)/2 ? Why or why not? Base case: (1-1)(1-2)/2= 0(-1)/2= 0 and T(1)=0 so the base case holds. Induction step: Assume T(n)= (n-1)(n-2)/2. We want to prove that T(n+1)= n(n-1)/2. The recurrence is T(n+1)= (n+1) -2 + T(n). By induction, T(n)= (n-1)(n-2)/2 and therefore, T(n+1) = n-1 + (n-1)(n-2)/2 = (n 2-n)/2= n(n-1)/2 as required. Assignment #1 Problem: Prove that the number of times the statement current= current.next; in the readRear method is equal to your hypothesized function f(n). Proof A: f(n)= (n-1)(n-2)/2 Proof B: f(n)= n(n-1)/2 Proof C: f(n)= n-1 Proof D: f(n)= n+1 The 4 proofs are very similar in wording. Which one should you believe? Do any of these have enough information to convince you that the f(n) is correct? Proof B: Let T(n) be the number of times the statement current= current.next ; is executed for an input of size n. We want to prove that T(n)= n(n-1)/2 . Base case: (1)(1-1)/2= 1(0)/2= 0 and T(1)=0 so the base case holds. Induction step: Assume T(n)= n(n-1)/2. We want to prove that T(n+1)= (n+1)n/2. The recurrence is T(n+1)= (n+1) -1 + T(n). By induction, T(n)= n(n-1)/2 and therefore, T(n+1) = n + n(n-1)/2 = (n 2 +n)/2= n(n+1)/2 as required. Proof C: Let T(n) be the number of times the statement current= current.next ; is executed for an input of size n. We want to prove that T(n)= n-1 . Base case: 1-1=0 and T(1)=0 so the base case holds. Induction step: Assume T(n)= n-1. We want to prove that T(n+1)= n. The recurrence is T(n+1)= 1 + T(n). By induction, T(n)= n-1 and therefore, T(n+1) = 1 + n-1 = n as required. Proof D: Let T(n) be the number of times the statement current= current.next ; is executed for an input of size n. We want to prove that T(n)= n+1 . Base case: 1+1=2 and T(1)=2 so the base case holds. Induction step: Assume T(n)= n+1. We want to prove that T(n+1)= n+2. The recurrence is T(n+1)= 1 + T(n). By induction, T(n)= n+1 and therefore, T(n+1) = 1 + n+1 = n+2 as required. 6 Heapsort Madame Trash Heap A Compost Heap Pictures from: http://www.compostinfo.com/tutorial/methods.htm http://linguiniontheceiling.blogspot.com/ 7 Max-heap: The data value at each node is greater than or equal to the data values of its children. 8 Left complete binary tree- fill in last level of a complete binary tree from left to right....
View Full Document

Page1 / 55

225_13_heap - Let T(n) be the number of times the statement...

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

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