Login Register


Hashing Superior to Binary search filter_list
Author
Message
Hashing Superior to Binary search #1
I wish to know why is hashing superior to Binary search.

Got a test the next week on Searching and Hashing. That idiot professor said "There will be a SURPRISE test on MONDAY." :troll:
[Image: MUJ8qSW.png]
-----------------------------------
Now learning:
Android Development, Java
Working on:
An FTP Client for Android
-----------------------------------

Reply

RE: Hashing Superior to Binary search #2
(05-27-2014, 04:03 PM)alok9shm Wrote: I wish to know why is hashing superior to Binary search.
I assume that in your case "superior" means "superior for searching purposes". I suggest you to read Search by Hashing - Boston University.

First you have to consider that a binary search requires the list/array to be sorted, the hash table has not such a requirement.

In the worst case, a binary search will cost you O(log(n)), while hashing will cost O(n); however hashing average performance is much better (under certain circumstances its cost belongs to O(1), that is constant time).

The actual cost of a hashing search actually depend on what hashing strategy you are considering. In the easiest case, each element of your domain will map to distinct locations of the hash table: this is not space-efficient, but lets you implement a search operation costing O(1).

You can have a hybrid strategy which combines hash tables and binary search: consider a hash table whose elements are sorted lists/arrays. Elements of your domain will collapse to the same locations in the hash table (that's a collision); when this happens, new elements will be inserted into the sorted list.
The worst-case cost of a search operation in this type of structure would be O(log(n/m)), where n is the number of elements, and m the number of locations in the hash table. To be honest, this cost could be better defined using some statistical considerations, and the topic is quite more complex, but I don't think you really need this for your "surpise" next monday. Wink

Reply







Users browsing this thread: