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

Hashing using search trees instead of lists

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

Problem

I am struggling with hashing and binary search tree material.
And I read that instead of using lists for storing entries with the same hash values, it is also possible to use binary search trees. And I try to understand what the worst-case and average-case running time for the operations

  • insert,



  • find and



  • delete



is in worth- resp. average case. Do they improve with respect to lists?

Solution

For lists, insertion, find and delete are respectively in $O(1)$, $O(n)$, $O(n)$. Sorted list are worse. Binary search itself is for sorted arrays, in which the operations are in $O(n)$, $O(\log n)$, $O(n)$. If you want "insertion" and "delete" operations then you need more than just binary search.

You probably want something like binary search trees. It is a lot easier to find references about it once you have the proper terminology. These operations are in $O(\log n)$ worst-case time, for example for the implementations using AVL trees and red-black trees.

Context

StackExchange Computer Science Q#1739, answer score: 4

Revisions (0)

No revisions yet.