Lecture 7.pptx - Lecture 7 Handling a Case Statement...

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

View Full Document Right Arrow Icon
Lecture 7
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
Handling a Case Statement condition1 true false condition2 true false Condition 3 true false condition2 true false
Image of page 2
First Function in Problem 3 MaxHeapify(A, i) l = left(i) r = right(i) if l <= heapsize and A[l] > A[i] then largest = l else largest = i if r <= heapsize and A[r] > A[largest] then largest = r if largest != i then swap A[i] with A[largest] MaxHeapify(A, largest) end func l a r g l e s t = l qq sta rts start l r end cond1 cond2 cond3 Largest=l Largest=i Largest=r swap MaxHeapify
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
Second Function in Problem 3 BuildMaxHeap(A) Heapsize = length[A] for i = |length[A]/2| downto 1 do MaxHeapify(A, i) end func start heap= i= i>=1? Max…. i=i-1 End
Image of page 4
Third Function in Problem 3 HeapSort(A) BuildMaxHeap(A) for i = length[A] downto 2 do swap A[1] with A[i] heapsize = heapsize – 1 MaxHeapify(A, 1) start BuildM i= i>=2? End Swap heap…. i=i-1 Max
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
Modeling Binary Search Operation index Meaning 1 Low = 1 2 High = n 3 Loc = 0 4 Middle = (low+high) DIV 2 5 X = table[middle]? 6 Loc= middle 7 Table[middle] > x ? 8 High = middle -1 9 Low = middle + 1 10 Low > high?
Image of page 6
Data Flow Graph for the Binary Search
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
Control Flow Graph Start e 1 e 8 e 7 e 3 e 9 e 0 e 10 e 6 e 2 e 4 e 5 e 1 e 8 e 10 e 2 e 3 e 4 e 5
Image of page 8
With these, the flow balance equations are developed. Flow Balance Equations e0 e6 e7 e9 Equation e1= e0 e1=1 e2= e0 +e9 e2=1+e9 e3= +e6 +e9 e3=e6+e9 e4= e0 -e6 e4=1-e6 e5= +e9 e5=e9 e8= -e7 +e9 e8=e9-e7 e10= e0 e10=1
Image of page 9

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

View Full Document Right Arrow Icon
Examination of the equation reveals there is a constant term, corresponding to initialization, it is a fixed time, and there are also data dependencies.
Image of page 10
Image of page 11
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