Skip to main content
Removed unnecessary information
Source Link
Mario Cervera
  • 3.8k
  • 2
  • 20
  • 22

An easy way to visualize this is to imagine a hash table of size $n$ (implemented with chaining) that contains all of the elements of $U$ (even though this is unrealistic in practice because $U$ typically has massive size). Since $|U| >> n$, all of the elements of $U$ do not fit into the hash table; therefore, there will be collisions. Consider, for example, the universal set $U=\{a,b,c,d,e,f,g\}$ and a hash table with $n=3$ buckets. Since $|U|=7$, at least one bucket must necessarily contain $\lceil \: |U| \: / \: n \rceil = \lceil 7/3 \rceil = 3$ or more elements. In the case of the most clever hash function (which would spread out the elements of $U$ as evenly as possible), this bucket would contain exactly $3$ elements, like this (highlighted in red):

Pathological data sets

It is important to see that no matter how clever the hash function is, there will always exist a data set (for example, the set $\{b,g,a\}$) whose elements hash to the same bucket (for example, bucket number $1$). Such a pathological data set will make your hash table degenerate to its worst-case linear-time performance. Contrast this worst-case data set with the set $\{b,f,e\}$, which will be spread out perfectly. In this case, the hash table will achieve constant time performance for insertions, deletions, and look-ups.

An easy way to visualize this is to imagine a hash table of size $n$ (implemented with chaining) that contains all of the elements of $U$ (even though this is unrealistic in practice because $U$ typically has massive size). Since $|U| >> n$, all of the elements of $U$ do not fit into the hash table; therefore, there will be collisions. Consider, for example, the universal set $U=\{a,b,c,d,e,f,g\}$ and a hash table with $n=3$ buckets. Since $|U|=7$, at least one bucket must necessarily contain $\lceil \: |U| \: / \: n \rceil = \lceil 7/3 \rceil = 3$ or more elements. In the case of the most clever hash function (which would spread out the elements of $U$ as evenly as possible), this bucket would contain exactly $3$ elements, like this (highlighted in red):

Pathological data sets

It is important to see that no matter how clever the hash function is, there will always exist a data set (for example, the set $\{b,g,a\}$) whose elements hash to the same bucket (for example, bucket number $1$). Such a pathological data set will make your hash table degenerate to its worst-case linear-time performance. Contrast this worst-case data set with the set $\{b,f,e\}$, which will be spread out perfectly. In this case, the hash table will achieve constant time performance for insertions, deletions, and look-ups.

An easy way to visualize this is to imagine a hash table of size $n$ (implemented with chaining) that contains all of the elements of $U$ (even though this is unrealistic in practice because $U$ typically has massive size). Since $|U| >> n$, all of the elements of $U$ do not fit into the hash table; therefore, there will be collisions. Consider, for example, the universal set $U=\{a,b,c,d,e,f,g\}$ and a hash table with $n=3$ buckets. Since $|U|=7$, at least one bucket must necessarily contain $\lceil \: |U| \: / \: n \rceil = \lceil 7/3 \rceil = 3$ or more elements. In the case of the most clever hash function (which would spread out the elements of $U$ as evenly as possible), this bucket would contain exactly $3$ elements, like this (highlighted in red):

Pathological data sets

It is important to see that no matter how clever the hash function is, there will always exist a data set (for example, the set $\{b,g,a\}$) whose elements hash to the same bucket (for example, bucket number $1$). Such a pathological data set will make your hash table degenerate to its worst-case linear-time performance.

Removed an unncecessary sentence
Source Link
Mario Cervera
  • 3.8k
  • 2
  • 20
  • 22

An easy way to visualize this is to imagine a hash table of size $n$ (implemented with chaining) that contains all of the elements of $U$ (even though this is unrealistic in practice because $U$ typically has massive size). Since $|U| >> n$, all of the elements of $U$ do not fit into the hash table; therefore, there will be collisions. Consider, for example, the universal set $U=\{a,b,c,d,e,f,g\}$ and a hash table with $n=3$ buckets. Since $|U|=7$, at least one bucket must necessarily contain $\lceil \: |U| \: / \: n \rceil = \lceil 7/3 \rceil = 3$ or more elements. In the case of the most clever hash function (which would spread out the elements of $U$ as evenly as possible), this bucket would contain exactly $3$ elements, like this (highlighted in red):

Pathological data sets

It is important to see that no matter how clever the hash function is, there will always exist a data set (for example, the set $\{b,g,a\}$) whose elements hash to the same bucket (for example, bucket number $1$), even if the hash table is empty. Such a pathological data set will make your hash table degenerate to its worst-case linear-time performance. Contrast this worst-case data set with the set $\{b,f,e\}$, which will be spread out perfectly. In this case, the hash table will achieve constant time performance for insertions, deletions, and look-ups.

An easy way to visualize this is to imagine a hash table of size $n$ (implemented with chaining) that contains all of the elements of $U$ (even though this is unrealistic in practice because $U$ typically has massive size). Since $|U| >> n$, all of the elements of $U$ do not fit into the hash table; therefore, there will be collisions. Consider, for example, the universal set $U=\{a,b,c,d,e,f,g\}$ and a hash table with $n=3$ buckets. Since $|U|=7$, at least one bucket must necessarily contain $\lceil \: |U| \: / \: n \rceil = \lceil 7/3 \rceil = 3$ or more elements. In the case of the most clever hash function (which would spread out the elements of $U$ as evenly as possible), this bucket would contain exactly $3$ elements, like this (highlighted in red):

Pathological data sets

It is important to see that no matter how clever the hash function is, there will always exist a data set (for example, the set $\{b,g,a\}$) whose elements hash to the same bucket (for example, bucket number $1$), even if the hash table is empty. Such a pathological data set will make your hash table degenerate to its worst-case linear-time performance. Contrast this worst-case data set with the set $\{b,f,e\}$, which will be spread out perfectly. In this case, the hash table will achieve constant time performance for insertions, deletions, and look-ups.

An easy way to visualize this is to imagine a hash table of size $n$ (implemented with chaining) that contains all of the elements of $U$ (even though this is unrealistic in practice because $U$ typically has massive size). Since $|U| >> n$, all of the elements of $U$ do not fit into the hash table; therefore, there will be collisions. Consider, for example, the universal set $U=\{a,b,c,d,e,f,g\}$ and a hash table with $n=3$ buckets. Since $|U|=7$, at least one bucket must necessarily contain $\lceil \: |U| \: / \: n \rceil = \lceil 7/3 \rceil = 3$ or more elements. In the case of the most clever hash function (which would spread out the elements of $U$ as evenly as possible), this bucket would contain exactly $3$ elements, like this (highlighted in red):

Pathological data sets

It is important to see that no matter how clever the hash function is, there will always exist a data set (for example, the set $\{b,g,a\}$) whose elements hash to the same bucket (for example, bucket number $1$). Such a pathological data set will make your hash table degenerate to its worst-case linear-time performance. Contrast this worst-case data set with the set $\{b,f,e\}$, which will be spread out perfectly. In this case, the hash table will achieve constant time performance for insertions, deletions, and look-ups.

Minor changes to improve legibility and facilitate understanding
Source Link
Mario Cervera
  • 3.8k
  • 2
  • 20
  • 22

An easy way to visualize itthis is imaginingto imagine a hash table of size $n$ (implemented with chaining) that contains all of the elements of $U$ (even though this is unrealistic in practice because $U$ typically has massive size). Since $|U| >> n$, all of thesethe elements of $U$ do not fit into the hash table; therefore, there will be collisions. Consider, for example, the universal set $U=\{a,b,c,d,e,f,g\}$ and a hash table with $n=3$ buckets. Since $|U|=7$, at least one bucket must necessarily contain $\lceil \: |U| \: / \: n \rceil = \lceil 7/3 \rceil = 3$ or more elements. In the case of the most clever hash function (which would spread out the elements of $U$ as evenly as possible), this bucket would contain exactly $3$ elements, like this (highlighted in red):

Pathological data sets

The upshotIt is: important to see that no matter how clever the hash function is, there iswill always going to exist a data set (for example, the set $\{b,g,a\}$) whose elements hash to the same bucket (for example, bucket number $1$), even if the hash table is empty. Such a pathological data set will make your hash table degenerate to its worst-case linear-time performance. Contrast this worst-case data set with the set $\{b,f,e\}$, which will be spread out perfectly. In this case, the hash table will achieve constant time performance for insertions, deletions, and look-ups.

An easy way to visualize it is imagining a hash table of size $n$ (implemented with chaining) that contains all of the elements of $U$ (even though this is unrealistic in practice because $U$ typically has massive size). Since $|U| >> n$, all of these elements do not fit into the hash table; therefore, there will be collisions. Consider, for example, the universal set $U=\{a,b,c,d,e,f,g\}$ and a hash table with $n=3$ buckets. Since $|U|=7$, at least one bucket must necessarily contain $\lceil \: |U| \: / \: n \rceil = \lceil 7/3 \rceil = 3$ or more elements. In the case of the most clever hash function (which would spread out the elements of $U$ as evenly as possible), this bucket would contain exactly $3$ elements, like this (highlighted in red):

Pathological data sets

The upshot is: no matter how clever the hash function is, there is always going to exist a data set (for example, the set $\{b,g,a\}$) whose elements hash to the same bucket (for example, bucket number $1$), even if the hash table is empty. Such a pathological data set will make your hash table degenerate to its worst-case linear-time performance. Contrast this worst-case data set with the set $\{b,f,e\}$, which will spread out perfectly. In this case, the hash table will achieve constant time performance for insertions, deletions, and look-ups.

An easy way to visualize this is to imagine a hash table of size $n$ (implemented with chaining) that contains all of the elements of $U$ (even though this is unrealistic in practice because $U$ typically has massive size). Since $|U| >> n$, all of the elements of $U$ do not fit into the hash table; therefore, there will be collisions. Consider, for example, the universal set $U=\{a,b,c,d,e,f,g\}$ and a hash table with $n=3$ buckets. Since $|U|=7$, at least one bucket must necessarily contain $\lceil \: |U| \: / \: n \rceil = \lceil 7/3 \rceil = 3$ or more elements. In the case of the most clever hash function (which would spread out the elements of $U$ as evenly as possible), this bucket would contain exactly $3$ elements, like this (highlighted in red):

Pathological data sets

It is important to see that no matter how clever the hash function is, there will always exist a data set (for example, the set $\{b,g,a\}$) whose elements hash to the same bucket (for example, bucket number $1$), even if the hash table is empty. Such a pathological data set will make your hash table degenerate to its worst-case linear-time performance. Contrast this worst-case data set with the set $\{b,f,e\}$, which will be spread out perfectly. In this case, the hash table will achieve constant time performance for insertions, deletions, and look-ups.

Symplified answer
Source Link
Mario Cervera
  • 3.8k
  • 2
  • 20
  • 22
Loading
added 37 characters in body
Source Link
Mario Cervera
  • 3.8k
  • 2
  • 20
  • 22
Loading
Extended last paragraph
Source Link
Mario Cervera
  • 3.8k
  • 2
  • 20
  • 22
Loading
Improved picture and also legibility
Source Link
Mario Cervera
  • 3.8k
  • 2
  • 20
  • 22
Loading
Slightly updated picture
Source Link
Mario Cervera
  • 3.8k
  • 2
  • 20
  • 22
Loading
Improved legibility
Source Link
Mario Cervera
  • 3.8k
  • 2
  • 20
  • 22
Loading
Source Link
Mario Cervera
  • 3.8k
  • 2
  • 20
  • 22
Loading