table - Expected number of hash collisions -



table - Expected number of hash collisions -

i sense i'm way overthinking problem, here goes anyway...

i have hash table m slots in internal array. need insert n elements hash table. assuming have hash function randomly inserts element slot equal probability each slot, what's expected value of total number of hash collisions?

(sorry more of math question programming question).

edit: here's code have simulate using python. i'm getting numerical answers, having problem generalizing formula , explaining it.

import random import pdb n = 5 m = 8 num_iter = 100000 def get_collisions(table): col = 0 item in table: if item > 1: col += (item-1) homecoming col def run(): table = [0 x in range(m)] in range(n): table[int(random.random() * m)] += 1 #print table homecoming get_collisions(table) # main total = 0 in range(num_iter): total += run() print float(total)/num_iter

you'll find reply here: quora.com. expected number of collisions m buckets , n inserts is

n - m * (1 - ((m-1)/m)^n).

table hash collision

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -