Lecture 2 - Hashing Flashcards

1
Q

Give time worst case analysis of Insertion, Deletion, and Searching in hashing.

A

Insertion: O(1) time (Insert at the beginning of the list).

Deletion: Search time + O(1) if we use a double linked list.

Search: Worst time happens when all keys go the same slot (list of size n), and we need to scan the full list => O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Prove that expected time of search in hashing is Q(1+α)

where α = n/m.

A

Two cases:
1. Unsuccessful search
• Assume that we can compute the hash function in O(1) time.
• An unsuccessful search requires to scan all the keys in the list.
Search time = O( 1 + average length of lists )
Let ni be the length of the list attached to slot i.
E(ni) = α
=> O( 1 ) + O( α ) = O( 1 + α )

  1. Successful search
    • Assume the position of the searched key x is equally likely to be any of the elements stored in the list.
    • New keys inserted at the head of the list ⇒ Keys scanned after
    finding x have been inserted in the hash table before x.
    • Use indicator to count the number of collisions:
    Xij = I {h(ki) = h(kj)}; E(Xij) = 1/m(probability of a collision)

Bunch of math to show Q(1+alpha) (slide 10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly