Why is a Hash Table not used instead of a B-T...
Why is a Hash Table not used instead of a B-T...
There are several key reasons why databases typically use B-Trees instead of hash tables for indexing:
B-Trees support range queries and ordered access, while hash tables only support equality lookups. With a B-Tree, you can efficiently find all records between two values, or the first N records in sorted order. Hash tables cannot do this[1][2].
B-Trees have better worst-case performance. Hash table lookups are O(1) on average, but can degrade to O(n) if there are many collisions. B-Tree lookups are O(log n) in the worst case[1][2].
B-Trees are more space efficient. Hash tables need to allocate extra space for the hash array, and performance degrades if the load factor gets too high. B-Trees only store what they need[2].
B-Trees are more robust to memory constraints. If data doesn't fit in memory, B-Trees can efficiently page data in and out from disk. Hash tables require the entir...
expert
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào