Binary Search Tree vs Hash Table?

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值