2c03-review - 00060

2c03-review - 00060 - alone the path from leaf to root,...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
3 7 7 7 repair inset(1) repair 5 9 5 9 3 9 3 6 8 10 3 6 8 10 2 5 8 10 2 4 2 4 1 4 6 1 3.[20] a[10], b[10], Solutions at the end. 4.[10] Consider ADT Sets with the following operations: MEMBER, DELETE, INSERT. Show that a heap is not an efficient way to implement this ADT. What would you recommend? Is there a best implementations? If not, explain under what conditions which implementation might be consider as a good one? Provide big O estimations of the ADT operations for each implementation. For heap we have: The time complexity of MEMBER is O(n), because you have to check all nodes to find of if x is in heap in the worst time. The time complexity of DELETE is O(n), because you have to find out the position of x in the heap, just like what MEMBER do. After delete the element, we need O(log n) to reconstruct the heap. So, total O(n). The time complexity of INSERT is O(log n), because you just need to repair the heap
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: alone the path from leaf to root, which takes O(log n). Clearly, heap is not efficient for operation MEMBER and DELETE. The recommended ADT will be 2-3 tree and AVL tree and Binary Search Trees if we can guarantee the randomness of data. Both 2-3 and AVL have O(log n) time worst case complexity for all three operations, Binary Search Trees have O(log n) average case complexity. There is no best implementation. If the amount of data is large, 2-3 tree and AVL tree are better. However, if the amount of data is small, heap can be a good implementation, because the overhead for the reconstruction of 2-3 tree and AVL tree is quite large. In addition, if, space efficiency is more concerned, AVL tree is better, because 2-3 tree requires more memory for interior nodes. If we can guarantee the randomness, binary search trees are the best....
View Full Document

Ask a homework question - tutors are online