Why Red-black trees are preferred over hash tables though hash tables have constant time complexity?

Nguyễn Pháp

New member
Why Red-black trees are preferred over hash tables though hash tables have constant time complexity?
A. no they are not preferred
B. because of resizing issues of hash table and better ordering in redblack trees
C. because they can be implemented using trees
D. because they are balanced
 
Answer: B
Explanation: Redblack trees have O(logn) for ordering elements in terms of finding first and next elements. also whenever table size increases or decreases in hash table you need to perform rehashing which can be very expensive in real time. also red black stores elements in sorted order rather than input order.
 

Tìm kiếm

Back
Top