Sie sind auf Seite 1von 14

International University of Sarajevo

Probability and Hashing

Discrete Mathematics II

Done by:

Lejla Tašaković

Nizama Šemić Prof. Dr. Džejla Međedović


Abstract

Our project was to analyze the behavior of hashing with chaining using the
balls-and-bins simulations . The balls-and- bins problem is a classic problem
in probability theory that has many applications in computer science. The problem
involves m balls and n bins, and, in order to answer on this problem, we wrote a code that
throws n balls uniformly randomly into m bins. Also, we answered od three main
questions :
1) How many of bins were empty?
2) How many bins had more than average (n/m) number of balls, how many had more
than twice the average (2n/m) number of balls?
3) How full was the fullest bin?

In the end, in order to get a fairly reliable statistic, we have launched our code
50 times for each one of these experiments.
Project implementation

1) Question :How many of bins were empty?

Input : m=16 , n=16 ;


Output:
Minimum number of empty bins: 3
Maximum number of empty bins: 8
Average number of empty bins: 5
Input: m=128, n=128;
Output:
Minimum number of empty bins: 40
Maximum number of empty bins: 53
Average number of empty bins: 47

Input: m=1024, n=1024;


Output:
Minimum number of empty bins: 358
Maximum number of empty bins: 404
Average number of empty bins: 377
Input: m= 2^14, n=2^14;
Output:
Minimum number of empty bins: 5929
Maximum number of empty bins: 6120
Average number of empty bins: 6023

Input: m=8, n=32;


Output:
Minimum number of empty bins: 0
Maximum number of empty bins: 1
Average number of empty bins: 0
Input: m=128, n=1024;
Output:
Minimum number of empty bins: 0
Maximum number of empty bins: 1
Average number of empty bins: 0

Input: m=1024, n=16384;


Output:
Minimum number of empty bins: 0
Maximum number of empty bins: 0
Average number of empty bins: 0
2) Question : How many bins had more than average (n/m) number of
balls, how many had more than twice the average (2n/m) number of
balls?

Input : m=16 , n=16 ;


Output:
The bins with more than n/m balls per iteration: 4
The number of bins with more than 2n/m balls per iteration: 2
Input: m=128, n=128;
Output:
The bins with more than n/m balls per iteration: 33
The number of bins with more than 2n/m balls per iteration: 10

Input: m=1024, n=1024;


Output:
The bins with more than n/m balls per iteration: 280
The number of bins with more than 2n/m balls per iteration: 77
Input: m= 2^14, n=2^14;
Output:
The bins with more than n/m balls per iteration: 4357
The number of bins with more than 2n/m balls per iteration: 1314

Input: m=8, n=32;


Output:
The bins with more than n/m balls per iteration: 4
The number of bins with more than 2n/m balls per iteration: 0
Input: m=128, n=1024;
Output:
The bins with more than n/m balls per iteration: 50
The number of bins with more than 2n/m balls per iteration: 1

Input: m=1024, n=16384;


Output:
The bins with more than n/m balls per iteration: 445
The number of bins with more than 2n/m balls per iteration: 0
3) Question : How full was the fullest bin?

Input : m=16 , n=16 ;


Output: The fullest bin has:5,meaning it has 0. 3125% balls
Input: m=128, n=128;
Output: Fullest bin has 6, meaning it has 0.046875% balls

Input: m=1024, n=1024;


Output:

Input: m= 2^14, n=2^14;


Output:
Input: m=8, n=32;
Output:

Input: m=128, n=1024;


Output:

Input: m=1024, n=16384;


Output:

Das könnte Ihnen auch gefallen