{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 7.pptx

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

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

View Full Document Right Arrow Icon
Lecture 7
Background image of page 1

Info iconThis 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
Background 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
Background image of page 3

Info iconThis 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
Background 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
Background image of page 5

Info iconThis 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?
Background image of page 6
Data Flow Graph for the Binary Search
Background image of page 7

Info iconThis 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
Background 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
Background image of page 9

Info iconThis 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.
Background 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 ]}