I am currently bushing up on my data structures and basic algorithms, part of that is the Binary Tree. I do understand the algorithms, and how to implement a binary search tree and such. I do so how smart it is that we can do lookups in O(log n) time.
I am however having a hard time finding an example of when I would use a binary tree, where a hash tables would not do the same/better job. I have been doing some searching around and found that it is used for 3D graphis, something about what items are to be displayed, i do however have a hard time relating to this.
Can any one give me an example where it would be better to user a binary tree over a hash table?
Asked By : Androme
Answered By : Aaron
Hash tables can only tell you if an element is present or not.
Here are somethings you can do with a binary tree that you can't do wiht a hash table.
- sorted traversal of the tree
- find the next closest element
- find all elements less than or greater than a certain value
See this wikipedia article on K-d trees for an example of a real world data structure that makes use of the special properties of binary trees. http://en.wikipedia.org/wiki/K-d_tree
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/30347
0 comments:
Post a Comment
Let us know your responses and feedback