»
Searching for an element requires O(log n) time, contrasted to O(n) time for a
binary heap.
»
Printing the elements in order requires only O(log n) time, contrasted to O(n
log n) time for a binary heap.
»
Finding the floor and ceiling requires O(log n) time.
»
Locating Kth smallest/largest element requires O(log n) time when the tree is
properly configured.
Whether these times are important depends on your application. BST tends to
work best in situations in which you spend more time searching and less time
building the tree. A binary heap tends to work best in dynamic situations in which
keys change regularly. The binary heap also offers advantages, as described in the
following list:
FIGURE 7-2:
The arrangement
of keys when
using a binary
heap.
CHAPTER 7
Do'stlaringiz bilan baham: |