This preview shows pages 1–9. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full 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)= (n1)(n2)/2 ? Why or why not? Base case: (11)(12)/2= 0(1)/2= 0 and T(1)=0 so the base case holds. Induction step: Assume T(n)= (n1)(n2)/2. We want to prove that T(n+1)= n(n1)/2. The recurrence is T(n+1)= (n+1) 2 + T(n). By induction, T(n)= (n1)(n2)/2 and therefore, T(n+1) = n1 + (n1)(n2)/2 = (n 2n)/2= n(n1)/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)= (n1)(n2)/2 Proof B: f(n)= n(n1)/2 Proof C: f(n)= n1 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(n1)/2 . Base case: (1)(11)/2= 1(0)/2= 0 and T(1)=0 so the base case holds. Induction step: Assume T(n)= n(n1)/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(n1)/2 and therefore, T(n+1) = n + n(n1)/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)= n1 . Base case: 11=0 and T(1)=0 so the base case holds. Induction step: Assume T(n)= n1. We want to prove that T(n+1)= n. The recurrence is T(n+1)= 1 + T(n). By induction, T(n)= n1 and therefore, T(n+1) = 1 + n1 = 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 Maxheap: 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
 Spring '10
 VALERIEKING

Click to edit the document details