Difference between pages "4.19" and "5.15"

From The Algorithm Design Manual Solution Wiki
(Difference between pages)
Jump to navigation Jump to search
(Created page with "1) Finding the maximum element is O(1) in both a max-heap (the root of the heap) and a sorted array (the last element in the array), so for this operation, both data structure...")
 
(Created page with " Back to Chapter 5")
 
Line 1: Line 1:
1) Finding the maximum element is O(1) in both a max-heap (the root of the heap) and a sorted array (the last element in the array), so for this operation, both data structures are equally optimal. (The max-heap is ''marginally'' faster, since the array length doesn't need to be accessed, but this splits hairs.)
 
  
2) Assuming the index of the element is known, a deletion on a heap costs O(log n) time to bubble down.  A sorted array requires all elements to be updated leading to a O(n) operation.
 
  
3) A heap can be formed in O(n) time.  The sorted array will require a sort costing O(n log n).
+
Back to [[Chapter 5]]
 
 
4) Finding the minimum element in a max-heap requires visiting each of the leaf nodes in the worst case, i.e. is an O(n) operation. Finding the minimum element in a sorted array is an O(1) operation (it's the first element), so the sorted array performs (asymptotically) better.
 
 
 
 
 
Back to [[Chapter 4]]
 

Latest revision as of 00:56, 21 September 2020


Back to Chapter 5