Yelp Interview Question

If memory is limited, which data structure is better: hashtable or binary tree?

Interview Answers

Anonymous

Dec 27, 2010

binary tree is better if memory is limited...

2

Anonymous

Oct 7, 2011

To add more to the above answer. Binary trees use memory in proportion to the data that is to be stored - the data and links. For a hash table, if the hash function has a huge range, you will have to allocate an array that has an entry for each number in the range. You could potentially store far lesser number of elements than the range.

1