http://answers.yahoo.com/question/index;_ylt=A0SO8wNZTdFS3GwAXqJXNyoA;_ylu=X3oDMTEzMDc5Z2d1BHNlYwNzcgRwb3MDMQRjb2xvA2dxMQR2dGlkA1ZJUDI4M18x?qid=20090612072730AAnGAb0
Binary Search Tree vs Hash Table?
peti asked 5 years ago
Hello,
in have implemented a dictionary, that has pair(char* key, char * definition) elements ( C++) using a Binary Search Tree.
In the documentation i need to enumerate some of the advantages and disadvantages of using a BST over a Hash table as a representation.
I already know that using a Hash Table would be faster but a lot more memory consuming. Any other differences? Also can someone please tell me the complexities involved in both parts?
Thanks! ill choose a best answer ASAP so dont be shy.
Additional Details
Also , how about Linked Lists, how do they compare to the other 2 Data structures?
5 years ago
Answer
Follow Watchlist
Best AnswerVoter's Choice
absolt123 answered 5 years ago
Binary search tree has worst case seek of O(n) if elements are inserted in order.
Hash table has worst case seek of O(n) if every element hashes to the same value.
Assuming you have a good hash functions, a hash table will be very close to O(1) for both inserts and look-ups.
If you balance your btree, you will end up with O(lg n) lookups.
For the same number of elements, a btree will usually be more compact.
However, a good hash table is notoriously hard to implement where as a good binary tree is, even balanced, is fairly straight forward. Hash functions are very subtle and finicky so picking a good one for your data set will take some work.
1 Comment
Other Answers (1)
Gregory W answered 5 years ago
An advantage of a binary tree is that you can print out the Dictionary in order the hash file is in no particular order.
A disadvantage of a binary tree is if you fill it from an alphabelical list - it will be unbalanced
Rate Comment
Binary Search Tree vs Hash Table?
peti asked 5 years ago
Hello,
in have implemented a dictionary, that has pair(char* key, char * definition) elements ( C++) using a Binary Search Tree.
In the documentation i need to enumerate some of the advantages and disadvantages of using a BST over a Hash table as a representation.
I already know that using a Hash Table would be faster but a lot more memory consuming. Any other differences? Also can someone please tell me the complexities involved in both parts?
Thanks! ill choose a best answer ASAP so dont be shy.
Additional Details
Also , how about Linked Lists, how do they compare to the other 2 Data structures?
5 years ago
Answer
Follow Watchlist
Best AnswerVoter's Choice
absolt123 answered 5 years ago
Binary search tree has worst case seek of O(n) if elements are inserted in order.
Hash table has worst case seek of O(n) if every element hashes to the same value.
Assuming you have a good hash functions, a hash table will be very close to O(1) for both inserts and look-ups.
If you balance your btree, you will end up with O(lg n) lookups.
For the same number of elements, a btree will usually be more compact.
However, a good hash table is notoriously hard to implement where as a good binary tree is, even balanced, is fairly straight forward. Hash functions are very subtle and finicky so picking a good one for your data set will take some work.
1 Comment
Other Answers (1)
Gregory W answered 5 years ago
An advantage of a binary tree is that you can print out the Dictionary in order the hash file is in no particular order.
A disadvantage of a binary tree is if you fill it from an alphabelical list - it will be unbalanced
Rate Comment
本文探讨了二叉搜索树(BinarySearchTree)与哈希表(HashTable)作为数据结构实现字典功能的优缺点。分析了两者在查找、插入操作的时间复杂度,并讨论了平衡二叉树与哈希函数选择的重要性。
498

被折叠的 条评论
为什么被折叠?



