{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

225_13_heap - LetT(n) current=current.next (n)=(n1(n2/2...

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

View Full Document Right Arrow Icon
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.
Image of page 1

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

View Full Document Right Arrow Icon
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? 
Image of page 2
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.
Image of page 3

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

View Full Document Right Arrow Icon
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.
Image of page 4
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.
Image of page 5

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

View Full Document Right Arrow Icon
6  Heapsort Madame Trash Heap A Compost Heap Pictures from: http://www.compostinfo.com/tutorial/methods.htm http://linguiniontheceiling.blogspot.com/
Image of page 6
7 Max-heap:  The data value at each node is greater than  or equal to the data values of its children.
Image of page 7

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

View Full Document Right Arrow Icon
8 Left complete binary tree-  fill in last level of a complete binary  tree from left to right.
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern