SlideShare a Scribd company logo
Name: Nguyen Thi Nha Trang
ID: IT060052
                                     ASSIGNMENT

        Why the size of the array of a hash table should be a prime number.


We have:

                       Arrayindex = hugeNumber % arraySize
Where:
  • Arrayindex is the array index where the object is stored.
  • hugeNumber is the hash value of the object to be stored.
  • arraySize is the length of the array of the hash table.


The reason why array’s size of a hash table should be a prime number is that it can help
to reduce the collisions.
To make it easier to understand, lets suppose that if the array’s size is not a prime
number, then the remainder of the modulo operation will return 0 for all hash values
which are divisible by the array’s size. This will cause collisions which would force the
hash table to switch on the collision resolution logic which is very complex. It also will
make the hash table to call Equals function to all previously stored objects with the same
hash value to find out if the same object was already stored. Therefore, the array’s size
should be a prime number to help avoiding the collisions after the operating of the
modulo function.

More Related Content

PPTX
PDF
PPTX
5 data structures-arraysandlinkedlist
PPTX
PPt. on An _Array in C
PPT
Lecture7
PPTX
PPTX
Arrays accessing using for loops
PPT
Programming Logic and Design: Arrays
5 data structures-arraysandlinkedlist
PPt. on An _Array in C
Lecture7
Arrays accessing using for loops
Programming Logic and Design: Arrays

What's hot (20)

PPTX
Arrays introduction- JAVA
PPTX
Data structures and algorithms arrays
PPTX
Data structure
PPTX
Types of Arrays
PPTX
Dsa – data structure and algorithms sorting
PPTX
PPTX
Data structures Lecture 5
PPTX
Workshop 04 Review
PDF
Learn Java Part 9
PDF
Binary search algorithm
PPTX
Binary search Algorithm
PDF
Data structure lecture 2 (pdf)
PDF
Arrays in java
PPTX
Dsa – data structure and algorithms searching
PDF
Learn Java Part 8
PPT
Mesics lecture 8 arrays in 'c'
DOCX
Quick sort
PPTX
PPTX
Hash table in data structure and algorithm
Arrays introduction- JAVA
Data structures and algorithms arrays
Data structure
Types of Arrays
Dsa – data structure and algorithms sorting
Data structures Lecture 5
Workshop 04 Review
Learn Java Part 9
Binary search algorithm
Binary search Algorithm
Data structure lecture 2 (pdf)
Arrays in java
Dsa – data structure and algorithms searching
Learn Java Part 8
Mesics lecture 8 arrays in 'c'
Quick sort
Hash table in data structure and algorithm
Ad

Similar to Assignment Algo (20)

PPT
computer notes - Data Structures - 37
PPTX
hashing in data strutures advanced in languae java
PPT
11_hashtable-1.ppt. Data structure algorithm
PPTX
Data Structures-Topic-Hashing, Collision
PDF
DSA UNIT II ARRAY AND LIST - notes
PPTX
Hashing and Collision Advanced data structure and algorithm
PPT
Array
PPT
Chapter 10: hashing data structure
PPTX
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
PPTX
Hashing And Hashing Tables
PDF
Assignment4 Assignment 4 Hashtables In this assignment we w.pdf
PPTX
Hashing
PDF
Sienna 9 hashing
PPTX
Hashing
PPTX
Hash based inventory system
PPTX
hashing in data structure for Btech .pptx
PPTX
hashing in data structure for engineering.pptx
PPTX
hashing in data structure for Btech.pptx
PPTX
Hashing Introduction , hash functions and techniques
PDF
Java arrays (1)
computer notes - Data Structures - 37
hashing in data strutures advanced in languae java
11_hashtable-1.ppt. Data structure algorithm
Data Structures-Topic-Hashing, Collision
DSA UNIT II ARRAY AND LIST - notes
Hashing and Collision Advanced data structure and algorithm
Array
Chapter 10: hashing data structure
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
Hashing And Hashing Tables
Assignment4 Assignment 4 Hashtables In this assignment we w.pdf
Hashing
Sienna 9 hashing
Hashing
Hash based inventory system
hashing in data structure for Btech .pptx
hashing in data structure for engineering.pptx
hashing in data structure for Btech.pptx
Hashing Introduction , hash functions and techniques
Java arrays (1)
Ad

Assignment Algo

  • 1. Name: Nguyen Thi Nha Trang ID: IT060052 ASSIGNMENT Why the size of the array of a hash table should be a prime number. We have: Arrayindex = hugeNumber % arraySize Where: • Arrayindex is the array index where the object is stored. • hugeNumber is the hash value of the object to be stored. • arraySize is the length of the array of the hash table. The reason why array’s size of a hash table should be a prime number is that it can help to reduce the collisions. To make it easier to understand, lets suppose that if the array’s size is not a prime number, then the remainder of the modulo operation will return 0 for all hash values which are divisible by the array’s size. This will cause collisions which would force the hash table to switch on the collision resolution logic which is very complex. It also will make the hash table to call Equals function to all previously stored objects with the same hash value to find out if the same object was already stored. Therefore, the array’s size should be a prime number to help avoiding the collisions after the operating of the modulo function.