(-10,23,14,-2) # Divide step: Level 1 / \ (-10,23) (14,-2) # Divide step: Level 2 | | X # Sorting tuples (-10,23) (-2,14) # Conquer using merge \ / (-10,-2,14,23)
Merge
routine exists, we have
MergeSort(a,n): { if size(a) = 1 then return(a) elseif size(a) = 2 then if a[1] and a[2] are not in proper order, then swap(a[1],a[2]) endif else { split a into two lists of equal size, L and R return(Merge(MergeSort(L,n/2),MergeSort(R,n/2))) } endif }
+---+--+ +--+---+--+ +--+---+--+ +--+---+--+ +--+---+ | | |<--+-o| | |<--+-o| | |<--+-o| | |<--+-o| | | H | | | | A | | | | C | | | | D | | | | T | | |o-+-->| | |o-+-->| | |o-+-->| | |o-+-->| | | +---+--+ +--+---+--+ +--+---+--+ +--+---+--+ +--+---+
Answer:
el
. Step 2: el.value <- B
Work = 1 memory I/O
Step 3: el.prev <- ElementAt(2)
Work = 3 mem. I/O
Step 4: el.next <- ElementAt(3)
Work = 4 mem. I/O
Step 5: el.prev.next <- el
Work = 1 mem. I/O
Step 6: el.next.prev <- el
Work = 1 mem. I/O
Total Work = 10 memory I/O ops + 1 "new" operation
Answer:
Answer:
Answer:
Answer:
Answer:
(a) 5 Not a heap, since (i) 1 Swap (ii) 1 Swap / \ 5 > 1 < 6 . / \ 1&5 / \ 2&5 1 4 5 4 2 4 / \ / \ / \ MIN- 6 2 6 2 6 5 HEAP (b) 6 Is a MIN-HEAP / \ 7 8 / \ \ 8 9 10 (c) 22 Not a heap, since (i) 22 Rotate (ii) 46 Swap / \ 22 < 46 > 21 / \ Left / \ 46&22 13 46 violates heap-order 46 13 22 13 / \ / \ / \ MAX- 12 21 21 12 21 12 HEAP
Copyright © 1999 by Mark S. Schmalz.