HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

When are binary trees better than hashtables in real world applications?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
realhashtablesarethanbettertreesapplicationsworldbinarywhen

Problem

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?

Solution

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

Context

StackExchange Computer Science Q#30347, answer score: 14

Revisions (0)

No revisions yet.