ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.1 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | FAIL | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=800 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://mca.ignougroup.com/2017/01/why-is-it-best-to-use-prime-number-as.html |
| Last Crawled | 2026-04-15 18:59:38 (3 days ago) |
| First Indexed | 2025-06-01 14:07:00 (10 months ago) |
| HTTP Status Code | 200 |
| Meta Title | Why is it best to use a prime number as a mod in a hashing function? | MCA IGNOU GROUP |
| Meta Description | null |
| Meta Canonical | null |
| Boilerpipe Text | Question Detail:
If I have a list of key values from 1 to 100 and I want to organize them in an array of 11 buckets, I've been taught to form a mod function
$$ H = k \bmod \ 11$$
Now all the values will be placed one after another in 9 rows. For example, in the first bucket there will be $0, 11, 22 \dots$. In the second, there will be $1, 12, 23 \dots$ etc.
Let's say I decided to be a bad boy and use a non-prime as my hashing function - take 12. Using the Hashing function
$$ H = k \bmod \ 12$$
would result in a hash table with values $0, 12, 24 \dots $ in the first bucket, $1, 13, 25 \dots$ etc. in the second and so on.
Essentially they are the same thing. I didn't reduce collisions and I didn't spread things out any better by using the prime number hash code and I can't see how it is ever beneficial.
Asked By :
CodyBugstein
Answered By :
Mario Cervera
Consider the set of keys $K=\{0,1,...,100\}$ and a hash table where the number of buckets is $m=12$. Since $3$ is a factor of $12$, the keys that are multiples of $3$ will be hashed to buckets that are multiples of $3$:
Keys $\{0,12,24,36,...\}$ will be hashed to bucket $0$.
Keys $\{3,15,27,39,...\}$ will be hashed to bucket $3$.
Keys $\{6,18,30,42,...\}$ will be hashed to bucket $6$.
Keys $\{9,21,33,45,...\}$ will be hashed to bucket $9$.
If $K$ is uniformly distributed (i.e., every key in $K$ is equally likely to occur), then the choice of $m$ is not so critical. But, what happens if $K$ is not uniformly distributed? Imagine that the keys that are most likely to occur are the multiples of $3$. In this case, all of the buckets that are not multiples of $3$ will be empty with high probability (which is really bad in terms of hash table performance).
This situation is more common that it may seem. Imagine, for instance, that you are keeping track of objects based on where they are stored in memory. If your computer's word size is four bytes, then you will be hashing keys that are multiples of $4$. Needless to say that choosing $m$ to be a multiple of $4$ would be a terrible choice: you would have $3m/4$ buckets completely empty, and all of your keys colliding in the remaining $m/4$ buckets.
In general:
Every key in $K$ that shares a common factor with the number of buckets $m$ will be hashed to a bucket that is a multiple of this factor.
Therefore, to minimize collisions, it is important to reduce the number of common factors between $m$ and the elements of $K$. How can this be achieved? By choosing $m$ to be a number that has very few factors: a
prime number
. |
| Markdown | [World's most popular travel blog for travel bloggers.](http://circularjourney.com/?utm_source=mca-blog)
# [MCA IGNOU GROUP](https://mca.ignougroup.com/)
Download Solved Assignments 2017-2018, Solved Question Papers Best Answers from Yahoo.com, Quora.com, Stackoverflow.com, Ignou.ac.in, Solved Assignments, Solution to any question
- [Home](https://mca.ignougroup.com/)
- [Ask a Question](http://ask.ignougroup.com/)
- [Assignments](http://mca.ignougroup.com/p/assignments.html)
- [MCA 1st Sem](http://mca.ignougroup.com/p/assignments.html)
- [MCA 2nd Sem](http://mca.ignougroup.com/p/assignment-mca-2nd-semester-2015-2016.html)
- [MCA 3rd Sem](http://mca.ignougroup.com/p/ignou-mca-assignment-3rd-semester-2016.html)
- [MCA 4th Sem](http://mca.ignougroup.com/p/ignou-assignment.html)
- [MCA 5th Sem](http://mca.ignougroup.com/p/mca-5th-sem-solved-assignment.html)
- [Question Papers](http://mca.ignougroup.com/p/question-paper.html)
- [Contact](https://mca.ignougroup.com/2017/01/why-is-it-best-to-use-prime-number-as.html)
# Why is it best to use a prime number as a mod in a hashing function?
posted by ,
on
7:42:00 AM
, [No Comments](https://mca.ignougroup.com/2017/01/why-is-it-best-to-use-prime-number-as.html#comment-form)
**Question Detail:**
If I have a list of key values from 1 to 100 and I want to organize them in an array of 11 buckets, I've been taught to form a mod function
\$\$ H = k \\bmod \\ 11\$\$
Now all the values will be placed one after another in 9 rows. For example, in the first bucket there will be \$0, 11, 22 \\dots\$. In the second, there will be \$1, 12, 23 \\dots\$ etc.
Let's say I decided to be a bad boy and use a non-prime as my hashing function - take 12. Using the Hashing function
\$\$ H = k \\bmod \\ 12\$\$
would result in a hash table with values \$0, 12, 24 \\dots \$ in the first bucket, \$1, 13, 25 \\dots\$ etc. in the second and so on.
Essentially they are the same thing. I didn't reduce collisions and I didn't spread things out any better by using the prime number hash code and I can't see how it is ever beneficial.
###### Asked By : [CodyBugstein](http://cs.stackexchange.com/users/4348)
###### Best Answer from StackOverflow
Question Source : <http://cs.stackexchange.com/questions/11029>
#### Answered By : [Mario Cervera](http://cs.stackexchange.com/users/57681/)
Consider the set of keys \$K=\\{0,1,...,100\\}\$ and a hash table where the number of buckets is \$m=12\$. Since \$3\$ is a factor of \$12\$, the keys that are multiples of \$3\$ will be hashed to buckets that are multiples of \$3\$:
- Keys \$\\{0,12,24,36,...\\}\$ will be hashed to bucket \$0\$.
- Keys \$\\{3,15,27,39,...\\}\$ will be hashed to bucket \$3\$.
- Keys \$\\{6,18,30,42,...\\}\$ will be hashed to bucket \$6\$.
- Keys \$\\{9,21,33,45,...\\}\$ will be hashed to bucket \$9\$.
If \$K\$ is uniformly distributed (i.e., every key in \$K\$ is equally likely to occur), then the choice of \$m\$ is not so critical. But, what happens if \$K\$ is not uniformly distributed? Imagine that the keys that are most likely to occur are the multiples of \$3\$. In this case, all of the buckets that are not multiples of \$3\$ will be empty with high probability (which is really bad in terms of hash table performance).
This situation is more common that it may seem. Imagine, for instance, that you are keeping track of objects based on where they are stored in memory. If your computer's word size is four bytes, then you will be hashing keys that are multiples of \$4\$. Needless to say that choosing \$m\$ to be a multiple of \$4\$ would be a terrible choice: you would have \$3m/4\$ buckets completely empty, and all of your keys colliding in the remaining \$m/4\$ buckets.
In general:
> Every key in \$K\$ that shares a common factor with the number of buckets \$m\$ will be hashed to a bucket that is a multiple of this factor.
Therefore, to minimize collisions, it is important to reduce the number of common factors between \$m\$ and the elements of \$K\$. How can this be achieved? By choosing \$m\$ to be a number that has very few factors: a **prime number**.
- — Share It —
- [Facebook](http://www.facebook.com/sharer.php?u=&title=Why%20is%20it%20best%20to%20use%20a%20prime%20number%20as%20a%20mod%20in%20a%20hashing%20function?)
- [Twitter](http://twitter.com/share?url=https://mca.ignougroup.com/2017/01/why-is-it-best-to-use-prime-number-as.html&title=Why%20is%20it%20best%20to%20use%20a%20prime%20number%20as%20a%20mod%20in%20a%20hashing%20function?)
- [Google+](https://plus.google.com/share?url=https://mca.ignougroup.com/2017/01/why-is-it-best-to-use-prime-number-as.html&title=Why%20is%20it%20best%20to%20use%20a%20prime%20number%20as%20a%20mod%20in%20a%20hashing%20function?)
- [Linkedin](http://www.linkedin.com/shareArticle?mini=true&url=https://mca.ignougroup.com/2017/01/why-is-it-best-to-use-prime-number-as.html&title=Why%20is%20it%20best%20to%20use%20a%20prime%20number%20as%20a%20mod%20in%20a%20hashing%20function?)
- [Pin It](http://pinterest.com/pin/create/button/?url=https://mca.ignougroup.com/2017/01/why-is-it-best-to-use-prime-number-as.html&media=&description=Question%20Detail:%20%C2%A0%20If%20I%20have%20a%20list%20of%20key%20values%20from%201%20to%20100%20and%20I%20want%20to%20organize%20them%20in%20an%20array%20of%2011%20buckets,%20I've%20been%20taught%20...)
#### [Akshay Mishra](https://mca.ignougroup.com/2017/01/why-is-it-best-to-use-prime-number-as.html)
[Newer Post](https://mca.ignougroup.com/2017/01/convert-cfg-to-pda.html "Newer Post") [Older Post](https://mca.ignougroup.com/2017/01/why-are-some-programming-languages.html "Older Post") [Home](https://mca.ignougroup.com/)
#### 0 comments:
#### Post a Comment
Let us know your responses and feedback
## Search By Course Code
## Blog Archive
- [►]() [2022](https://mca.ignougroup.com/2022/) (166)
- [►]() [July](https://mca.ignougroup.com/2022/07/) (6)
- [►]() [June](https://mca.ignougroup.com/2022/06/) (84)
- [►]() [May](https://mca.ignougroup.com/2022/05/) (66)
- [►]() [February](https://mca.ignougroup.com/2022/02/) (10)
- [►]() [2021](https://mca.ignougroup.com/2021/) (46)
- [►]() [March](https://mca.ignougroup.com/2021/03/) (19)
- [►]() [February](https://mca.ignougroup.com/2021/02/) (27)
- [►]() [2019](https://mca.ignougroup.com/2019/) (10)
- [►]() [August](https://mca.ignougroup.com/2019/08/) (5)
- [►]() [May](https://mca.ignougroup.com/2019/05/) (1)
- [►]() [April](https://mca.ignougroup.com/2019/04/) (3)
- [►]() [February](https://mca.ignougroup.com/2019/02/) (1)
- [►]() [2018](https://mca.ignougroup.com/2018/) (230)
- [►]() [October](https://mca.ignougroup.com/2018/10/) (22)
- [►]() [September](https://mca.ignougroup.com/2018/09/) (45)
- [►]() [March](https://mca.ignougroup.com/2018/03/) (128)
- [►]() [January](https://mca.ignougroup.com/2018/01/) (35)
- [▼]() [2017](https://mca.ignougroup.com/2017/) (4698)
- [►]() [December](https://mca.ignougroup.com/2017/12/) (35)
- [►]() [November](https://mca.ignougroup.com/2017/11/) (4)
- [►]() [October](https://mca.ignougroup.com/2017/10/) (9)
- [►]() [September](https://mca.ignougroup.com/2017/09/) (58)
- [►]() [August](https://mca.ignougroup.com/2017/08/) (244)
- [►]() [July](https://mca.ignougroup.com/2017/07/) (1)
- [►]() [June](https://mca.ignougroup.com/2017/06/) (1)
- [►]() [April](https://mca.ignougroup.com/2017/04/) (6)
- [►]() [March](https://mca.ignougroup.com/2017/03/) (564)
- [►]() [February](https://mca.ignougroup.com/2017/02/) (1855)
- [▼]() [January](https://mca.ignougroup.com/2017/01/) (1921)
- [\[Solved\]: Polynomial-time algorithm with exponenti...](https://mca.ignougroup.com/2017/01/solved-polynomial-time-algorithm-with.html)
- [\[Solved\]: Compute the Hamming code with odd parity...](https://mca.ignougroup.com/2017/01/solved-compute-hamming-code-with-odd.html)
- [\[Solved\]: How to prove polynomial time equivalence?](https://mca.ignougroup.com/2017/01/solved-how-to-prove-polynomial-time.html)
- [\[Solved\]: Understanding Expected Running Time of R...](https://mca.ignougroup.com/2017/01/solved-understanding-expected-running.html)
- [\[Solved\]: Algorithm for constructing BST from post...](https://mca.ignougroup.com/2017/01/solved-algorithm-for-constructing-bst.html)
- [\[Solved\]: How to efficiently use an AVL tree to st...](https://mca.ignougroup.com/2017/01/solved-how-to-efficiently-use-avl-tree.html)
- [\[Solved\]: What is an "encoding" of a TM?](https://mca.ignougroup.com/2017/01/solved-what-is-encoding-of-tm.html)
- [\[Solved\]: Universal simulation of Turing machines](https://mca.ignougroup.com/2017/01/solved-universal-simulation-of-turing.html)
- [\[Solved\]: shortest cost tiling of path to x distance](https://mca.ignougroup.com/2017/01/solved-shortest-cost-tiling-of-path-to.html)
- [\[Solved\]: Carry-free multiplication operation](https://mca.ignougroup.com/2017/01/solved-carry-free-multiplication.html)
- [\[Solved\]: Why are loops faster than recursion?](https://mca.ignougroup.com/2017/01/solved-why-are-loops-faster-than.html)
- [\[Solved\]: The difference between theoretical compl...](https://mca.ignougroup.com/2017/01/solved-difference-between-theoretical.html)
- [\[Solved\]: What Is The Complexity of Implementing a...](https://mca.ignougroup.com/2017/01/solved-what-is-complexity-of.html)
- [\[Solved\]: how do I find a undecidable subset of a ...](https://mca.ignougroup.com/2017/01/solved-how-do-i-find-undecidable-subset.html)
- [\[Solved\]: Is there a "sorting" algorithm which ret...](https://mca.ignougroup.com/2017/01/solved-is-there-sorting-algorithm-which.html)
- [\[Solved\]: Difference between Binomial and Fibonacc...](https://mca.ignougroup.com/2017/01/solved-difference-between-binomial-and.html)
- [\[Solved\]: Adding a node between two others, minimi...](https://mca.ignougroup.com/2017/01/solved-adding-node-between-two-others.html)
- [\[Solved\]: Understanding Multilevel Caches](https://mca.ignougroup.com/2017/01/solved-understanding-multilevel-caches.html)
- [\[Solved\]: Please explain a greedy algorithm in a n...](https://mca.ignougroup.com/2017/01/solved-please-explain-greedy-algorithm.html)
- [\[Solved\]: Is the shadow ray in a Whitted ray trace...](https://mca.ignougroup.com/2017/01/solved-is-shadow-ray-in-whitted-ray.html)
- [\[Solved\]: SAT not reducible to 2SAT](https://mca.ignougroup.com/2017/01/solved-sat-not-reducible-to-2sat.html)
- [\[Solved\]: Proving Equivalence of 1-dimensional Cel...](https://mca.ignougroup.com/2017/01/solved-proving-equivalence-of-1.html)
- [\[Solved\]: For what special cases does this vertex ...](https://mca.ignougroup.com/2017/01/solved-for-what-special-cases-does-this.html)
- [\[Solved\]: Why is deciding regularity of a context-...](https://mca.ignougroup.com/2017/01/solved-why-is-deciding-regularity-of.html)
- [\[Solved\]: Algorithm to find a line that divides th...](https://mca.ignougroup.com/2017/01/solved-algorithm-to-find-line-that.html)
- [\[Solved\]: When are 2 decision/optimization problem...](https://mca.ignougroup.com/2017/01/solved-when-are-2-decisionoptimization.html)
- [\[Solved\]: Does this DFA have a solution?](https://mca.ignougroup.com/2017/01/solved-does-this-dfa-have-solution.html)
- [\[Solved\]: Nth number in a infinite sequence of num...](https://mca.ignougroup.com/2017/01/solved-nth-number-in-infinite-sequence.html)
- [\[Solved\]: How to find the element of the Digit Sum...](https://mca.ignougroup.com/2017/01/solved-how-to-find-element-of-digit-sum.html)
- [\[Solved\]: How to prove P\$\\neq\$NP?](https://mca.ignougroup.com/2017/01/solved-how-to-prove-pneqnp.html)
- [\[Solved\]: Getting minimum DFA for regular expressi...](https://mca.ignougroup.com/2017/01/solved-getting-minimum-dfa-for-regular.html)
- [\[Solved\]: Paxos: Accepting Proposals With Differen...](https://mca.ignougroup.com/2017/01/solved-paxos-accepting-proposals-with.html)
- [\[Solved\]: Automated optimization of 0-1 matrix vec...](https://mca.ignougroup.com/2017/01/solved-automated-optimization-of-0-1.html)
- [\[Solved\]: If A is poly-time reducible to B, is B p...](https://mca.ignougroup.com/2017/01/solved-if-is-poly-time-reducible-to-b.html)
- [\[Solved\]: Is the relation between the input and ou...](https://mca.ignougroup.com/2017/01/solved-is-relation-between-input-and.html)
- [\[Solved\]: How to show that the complement of a lan...](https://mca.ignougroup.com/2017/01/solved-how-to-show-that-complement-of.html)
- [\[Solved\]: Do non-computable functions grow asympto...](https://mca.ignougroup.com/2017/01/solved-do-non-computable-functions-grow.html)
- [\[Solved\]: Time complexity of solving a set of 2-sa...](https://mca.ignougroup.com/2017/01/solved-time-complexity-of-solving-set.html)
- [\[Solved\]: Tree decomposition - Fastest algorithm i...](https://mca.ignougroup.com/2017/01/solved-tree-decomposition-fastest.html)
- [\[Solved\]: Is this a proper Max Heap Data Structure](https://mca.ignougroup.com/2017/01/solved-is-this-proper-max-heap-data.html)
- [\[Solved\]: The most appropriate way to implement a ...](https://mca.ignougroup.com/2017/01/solved-most-appropriate-way-to.html)
- [\[Solved\]: Does PETSc really give speedup?](https://mca.ignougroup.com/2017/01/solved-does-petsc-really-give-speedup.html)
- [\[Solved\]: What's the difference between a stream a...](https://mca.ignougroup.com/2017/01/solved-whats-difference-between-stream.html)
- [\[Solved\]: Finding a 5-Pointed Star in polynomial time](https://mca.ignougroup.com/2017/01/solved-finding-5-pointed-star-in.html)
- [\[Solved\]: Efficient algorithm to find vertex with ...](https://mca.ignougroup.com/2017/01/solved-efficient-algorithm-to-find.html)
- [\[Solved\]: Computing FOLLOW sets for LL(1) grammar....](https://mca.ignougroup.com/2017/01/solved-computing-follow-sets-for-ll1_31.html)
- [\[Solved\]: Why not to take the unary representation...](https://mca.ignougroup.com/2017/01/solved-why-not-to-take-unary.html)
- [\[Solved\]: Set cover problem and the existence of s...](https://mca.ignougroup.com/2017/01/solved-set-cover-problem-and-existence.html)
- [\[Solved\]: Need a hint! Karger's algorithm versus K...](https://mca.ignougroup.com/2017/01/solved-need-hint-kargers-algorithm.html)
- [\[Solved\]: Why is T not a minimum spanning tree of G?](https://mca.ignougroup.com/2017/01/solved-why-is-t-not-minimum-spanning.html)
- [\[Solved\]: Is \$A\$ regular if \$A^{2}\$ is regular?](https://mca.ignougroup.com/2017/01/solved-is-regular-if-a2-is-regular.html)
- [\[Solved\]: How to calculate the size of a page in a...](https://mca.ignougroup.com/2017/01/solved-how-to-calculate-size-of-page-in.html)
- [\[Solved\]: The language of machines that accepts al...](https://mca.ignougroup.com/2017/01/solved-language-of-machines-that.html)
- [\[Solved\]: Linear time labeling algorithm for a tree?](https://mca.ignougroup.com/2017/01/solved-linear-time-labeling-algorithm.html)
- [\[Solved\]: Does a context-free grammar with multipl...](https://mca.ignougroup.com/2017/01/solved-does-context-free-grammar-with.html)
- [\[Solved\]: Visualizing a Non Deterministic Decider](https://mca.ignougroup.com/2017/01/solved-visualizing-non-deterministic.html)
- [\[Solved\]: Corresponding noun for "side-effect-free"?](https://mca.ignougroup.com/2017/01/solved-corresponding-noun-for-side.html)
- [\[Solved\]: Is there a difference between \$\\lambda x...](https://mca.ignougroup.com/2017/01/solved-is-there-difference-between_31.html)
- [\[Solved\]: Would it ever be possible for computer v...](https://mca.ignougroup.com/2017/01/solved-would-it-ever-be-possible-for.html)
- [\[Solved\]: Quantum computers and computable functions](https://mca.ignougroup.com/2017/01/solved-quantum-computers-and-computable.html)
- [\[Solved\]: BCNF Decomposition: Confusion regarding ...](https://mca.ignougroup.com/2017/01/solved-bcnf-decomposition-confusion.html)
- [\[Solved\]: Meaning of the Halting problem](https://mca.ignougroup.com/2017/01/solved-meaning-of-halting-problem.html)
- [\[Solved\]: Solve a recurrence by drawing the recurs...](https://mca.ignougroup.com/2017/01/solved-solve-recurrence-by-drawing.html)
- [\[Solved\]: Minimum weight triangulation](https://mca.ignougroup.com/2017/01/solved-minimum-weight-triangulation.html)
- [\[Solved\]: Commonly used Error Correcting Codes](https://mca.ignougroup.com/2017/01/solved-commonly-used-error-correcting.html)
- [\[Solved\]: Finding edges with minimal weight sum, s...](https://mca.ignougroup.com/2017/01/solved-finding-edges-with-minimal.html)
- [\[Solved\]: Heuristics & Constrain Satisfaction Prob...](https://mca.ignougroup.com/2017/01/solved-heuristics-constrain.html)
- [\[Solved\]: Definition of “c-competitive” algorithm](https://mca.ignougroup.com/2017/01/solved-definition-of-c-competitive.html)
- [\[Solved\]: Efficiently sampling shortest \$s\$-\$t\$ pa...](https://mca.ignougroup.com/2017/01/solved-efficiently-sampling-shortest-s.html)
- [\[Solved\]: Quantum computing roadmap](https://mca.ignougroup.com/2017/01/solved-quantum-computing-roadmap.html)
- [\[Solved\]: Bridge theorems for group theory and for...](https://mca.ignougroup.com/2017/01/solved-bridge-theorems-for-group-theory.html)
- [\[Solved\]: Context Free Grammar for language](https://mca.ignougroup.com/2017/01/solved-context-free-grammar-for-language.html)
- [\[Solved\]: Why Instruction Decode and Register Read...](https://mca.ignougroup.com/2017/01/solved-why-instruction-decode-and.html)
- [\[Solved\]: Using a counting semaphore as a binary s...](https://mca.ignougroup.com/2017/01/solved-using-counting-semaphore-as.html)
- [\[Solved\]: Distribute objects in a cube so that the...](https://mca.ignougroup.com/2017/01/solved-distribute-objects-in-cube-so.html)
- [\[Solved\]: What is the relationship between Turing ...](https://mca.ignougroup.com/2017/01/solved-what-is-relationship-between.html)
- [\[Solved\]: Generate random numbers from an interval...](https://mca.ignougroup.com/2017/01/solved-generate-random-numbers-from.html)
- [\[Solved\]: Complete examples of program correctness...](https://mca.ignougroup.com/2017/01/solved-complete-examples-of-program.html)
- [\[Solved\]: Shortest even path that goes through a v...](https://mca.ignougroup.com/2017/01/solved-shortest-even-path-that-goes.html)
- [\[Solved\]: Is it impossible to truly emulate a syst...](https://mca.ignougroup.com/2017/01/solved-is-it-impossible-to-truly.html)
- [\[Solved\]: Error in the use of asymptotic notation](https://mca.ignougroup.com/2017/01/solved-error-in-use-of-asymptotic.html)
- [\[Solved\]: Data structure to use for a consumable m...](https://mca.ignougroup.com/2017/01/solved-data-structure-to-use-for.html)
- [\[Solved\]: Happened-before and Causal order](https://mca.ignougroup.com/2017/01/solved-happened-before-and-causal-order.html)
- [\[Solved\]: Would removing the branch delay slots ch...](https://mca.ignougroup.com/2017/01/solved-would-removing-branch-delay.html)
- [\[Solved\]: "Not in big theta but in big O"](https://mca.ignougroup.com/2017/01/solved-not-in-big-theta-but-in-big-o.html)
- [\[Solved\]: Find which vertices to delete from graph...](https://mca.ignougroup.com/2017/01/solved-find-which-vertices-to-delete.html)
- [\[Solved\]: How to replace one symbol with two on Tu...](https://mca.ignougroup.com/2017/01/solved-how-to-replace-one-symbol-with.html)
- [\[Solved\]: What were the research outcomes of the U...](https://mca.ignougroup.com/2017/01/solved-what-were-research-outcomes-of.html)
- [\[Solved\]: Give a specific case where calling a pol...](https://mca.ignougroup.com/2017/01/solved-give-specific-case-where-calling.html)
- [\[Solved\]: What is the difference between a Transit...](https://mca.ignougroup.com/2017/01/solved-what-is-difference-between_31.html)
- [\[Solved\]: Don Knuth and MMIXAL vs. Chuck Moore and...](https://mca.ignougroup.com/2017/01/solved-don-knuth-and-mmixal-vs-chuck.html)
- [\[Solved\]: Examples of algorithms that have runtime...](https://mca.ignougroup.com/2017/01/solved-examples-of-algorithms-that-have.html)
- [\[Solved\]: Number of different output labels in Loc...](https://mca.ignougroup.com/2017/01/solved-number-of-different-output.html)
- [\[Solved\]: Is there a typed SKI calculus?](https://mca.ignougroup.com/2017/01/solved-is-there-typed-ski-calculus.html)
- [\[Solved\]: Reduction to complement of Accept Problem](https://mca.ignougroup.com/2017/01/solved-reduction-to-complement-of.html)
- [\[Solved\]: Problems Implementing Closures in Non-fu...](https://mca.ignougroup.com/2017/01/solved-problems-implementing-closures.html)
- [\[Solved\]: LALR(1) parsers and the epsilon transition](https://mca.ignougroup.com/2017/01/solved-lalr1-parsers-and-epsilon.html)
- [\[Solved\]: Unambiguity of Reverse Polish Notation](https://mca.ignougroup.com/2017/01/solved-unambiguity-of-reverse-polish.html)
- [\[Solved\]: Reduce variant of Vertex Cover to origin...](https://mca.ignougroup.com/2017/01/solved-reduce-variant-of-vertex-cover.html)
- [\[Solved\]: Turing machine with repeated strings](https://mca.ignougroup.com/2017/01/solved-turing-machine-with-repeated.html)
- [►]() [2016](https://mca.ignougroup.com/2016/) (273)
- [►]() [December](https://mca.ignougroup.com/2016/12/) (24)
- [►]() [November](https://mca.ignougroup.com/2016/11/) (14)
- [►]() [October](https://mca.ignougroup.com/2016/10/) (46)
- [►]() [September](https://mca.ignougroup.com/2016/09/) (55)
- [►]() [August](https://mca.ignougroup.com/2016/08/) (10)
- [►]() [July](https://mca.ignougroup.com/2016/07/) (2)
- [►]() [June](https://mca.ignougroup.com/2016/06/) (8)
- [►]() [May](https://mca.ignougroup.com/2016/05/) (4)
- [►]() [April](https://mca.ignougroup.com/2016/04/) (50)
- [►]() [March](https://mca.ignougroup.com/2016/03/) (36)
- [►]() [February](https://mca.ignougroup.com/2016/02/) (16)
- [►]() [January](https://mca.ignougroup.com/2016/01/) (8)
- [►]() [2015](https://mca.ignougroup.com/2015/) (103)
- [►]() [December](https://mca.ignougroup.com/2015/12/) (14)
- [►]() [November](https://mca.ignougroup.com/2015/11/) (39)
- [►]() [October](https://mca.ignougroup.com/2015/10/) (50)
- [►]() [2013](https://mca.ignougroup.com/2013/) (4)
- [►]() [May](https://mca.ignougroup.com/2013/05/) (4)
- [►]() [2012](https://mca.ignougroup.com/2012/) (1)
- [►]() [December](https://mca.ignougroup.com/2012/12/) (1)
## Popular Posts
- [Develop SRS for Online Admission System for a University. MCS-014 Assignment 1](https://mca.ignougroup.com/2015/10/develop-srs-for-online-admission-system.html)
Course Code: MCS-014 Course Title: Systems Analysis and Design Assignment Number: MCA (I)/014/Assignment/15-16 Maximum Marks: 100 ...
- [Suppose there is a table named as product in Oracle database with attributes as : product id, product name, product quality, product price, model and its description . Write JAVA program to insert, delete and display records of the table using JDBC.](https://mca.ignougroup.com/2017/08/suppose-there-is-table-named-as-product.html)
First Create Table in your Database create database SampleDB; use SampleDB; CREATE TABLE product ( product\_id Num...
- [](https://mca.ignougroup.com/2018/09/write-algorithm-draw-flow-chart-and.html)
[Write an algorithm, draw a flow chart and write its corresponding C program to convert a decimal number to its equivalent hexadecimal number.](https://mca.ignougroup.com/2018/09/write-algorithm-draw-flow-chart-and.html)
Ans. Algorithm: Step 1: Input NUM Step 2: LEN = 0 & Y=NUM Step 3: While (Y \> 0) HEXD\[LEN\]=Y%16...
- [](https://mca.ignougroup.com/2016/10/er-diagram-of-cab-booking-application.html)
[ER diagram of Cab Booking Application](https://mca.ignougroup.com/2016/10/er-diagram-of-cab-booking-application.html)
ER diagram of Cab Management System, Cab Booking System or Cab Mobile Application
- [Write a C program to perform the following operation on matrices D = A + (B \* C), where A, B and C are matrices of (3 X 3) size and D is the resultant matrix.](https://mca.ignougroup.com/2018/09/write-c-program-to-perform-following.html)
Ans. \#include\<stdio.h\> \#include\<conio.h\> Void main() { int a\[3\]\[3\],b\[3\]\[3\],c\[3\]\[3\],d\[3\]\[3\]; int i,j,k; for(i=0;...
- [Develop SRS for Online Admission System for a University. MCS-014 Assignment 1](https://mca.ignougroup.com/2015/10/develop-srs-for-online-admission-system_8.html)
Course Code: MCS-014 Course Title: Systems Analysis and Design Assignment Number: MCA (I)/014/Assignment/15-16 Maximum Marks: 100 Weightage:...
- [Question : Consider the following relations: Supplier(S\#,sname,status,city) Parts(P\#,pname,color,weight,city) -SP(S\#,P\#,quantity)](https://mca.ignougroup.com/2018/09/question-consider-following-relations.html)
Answer the following simple queries in SQL. a) Find name of supplier for city = “MUMBAI”. ...
- [What is “Copyright‟ protection? Explain its relevance in computer applications.](https://mca.ignougroup.com/2018/09/what-is-copyright-protection-explain.html)
Ans. A copyright is a form of protection provided by the laws of the United States to authors of "original works of authorship....
- [](https://mca.ignougroup.com/2018/09/draw-dfd-upto-2nd-level-for-online.html)
[Draw a DFD upto 2nd level for Online Examination System of an University. Make necessary assumptions required.](https://mca.ignougroup.com/2018/09/draw-dfd-upto-2nd-level-for-online.html)
- [SRS of Railway Reservation System](https://mca.ignougroup.com/2016/11/srs-of-railway-reservation-system.html)
Software Requirement Specification for Railway Reservation System The SRS for Railway Reservation System is given as follo...
## Label Cloud
[\#java](https://mca.ignougroup.com/search/label/%23java) (4) [2012](https://mca.ignougroup.com/search/label/2012) (2) [2016-17](https://mca.ignougroup.com/search/label/2016-17) (2) [2017-18](https://mca.ignougroup.com/search/label/2017-18) (8) [2018-2019](https://mca.ignougroup.com/search/label/2018-2019) (1) [Adder](https://mca.ignougroup.com/search/label/Adder) (1) [advance java](https://mca.ignougroup.com/search/label/advance%20java) (6) [Assignments](https://mca.ignougroup.com/search/label/Assignments) (109) [B.Ed result](https://mca.ignougroup.com/search/label/B.Ed%20result) (1) [basic java](https://mca.ignougroup.com/search/label/basic%20java) (46) [Bed resutl](https://mca.ignougroup.com/search/label/Bed%20resutl) (1) [C](https://mca.ignougroup.com/search/label/C) (1) [C\#](https://mca.ignougroup.com/search/label/C%23) (1) [Data and File Structures](https://mca.ignougroup.com/search/label/Data%20and%20File%20Structures) (4) [Data Types](https://mca.ignougroup.com/search/label/Data%20Types) (1) [DNS](https://mca.ignougroup.com/search/label/DNS) (1) [EMU8086](https://mca.ignougroup.com/search/label/EMU8086) (2) [Exam date sheet](https://mca.ignougroup.com/search/label/Exam%20date%20sheet) (1) [exams](https://mca.ignougroup.com/search/label/exams) (10) [Firewall](https://mca.ignougroup.com/search/label/Firewall) (1) [Ignou](https://mca.ignougroup.com/search/label/Ignou) (1) [Ignou MCA 1st Semester mcs012](https://mca.ignougroup.com/search/label/Ignou%20MCA%201st%20Semester%20mcs012) (1) [IGNOU MCA 5th SEM](https://mca.ignougroup.com/search/label/IGNOU%20MCA%205th%20SEM) (1) [IGNOU MCA fifth semester ASSIGNMENT FREE DOWNLOAD](https://mca.ignougroup.com/search/label/IGNOU%20MCA%20fifth%20semester%20ASSIGNMENT%20FREE%20DOWNLOAD) (3) [ignou MCS-014 Solved assignment](https://mca.ignougroup.com/search/label/ignou%20MCS-014%20Solved%20assignment) (1) [ignou MCS-051 solved assignment](https://mca.ignougroup.com/search/label/ignou%20MCS-051%20solved%20assignment) (3) [ignou MCS-052 solved assignment](https://mca.ignougroup.com/search/label/ignou%20MCS-052%20solved%20assignment) (9) [ignou MCS-053 solved assignment](https://mca.ignougroup.com/search/label/ignou%20MCS-053%20solved%20assignment) (7) [ignou MCSE-11 solved assignment](https://mca.ignougroup.com/search/label/ignou%20MCSE-11%20solved%20assignment) (2) [Ignou results](https://mca.ignougroup.com/search/label/Ignou%20results) (1) [Introduction to Database Management Systems](https://mca.ignougroup.com/search/label/Introduction%20to%20Database%20Management%20Systems) (1) [java](https://mca.ignougroup.com/search/label/java) (24) [java programming](https://mca.ignougroup.com/search/label/java%20programming) (5) [java-programming](https://mca.ignougroup.com/search/label/java-programming) (1) [Lab Manuals](https://mca.ignougroup.com/search/label/Lab%20Manuals) (3) [Lab Schedule](https://mca.ignougroup.com/search/label/Lab%20Schedule) (4) [Learn Java](https://mca.ignougroup.com/search/label/Learn%20Java) (12) [Linux OS](https://mca.ignougroup.com/search/label/Linux%20OS) (2) [MCA](https://mca.ignougroup.com/search/label/MCA) (1) [MCS-011](https://mca.ignougroup.com/search/label/MCS-011) (9) [MCS-012](https://mca.ignougroup.com/search/label/MCS-012) (23) [MCS-013](https://mca.ignougroup.com/search/label/MCS-013) (23) [MCS-014](https://mca.ignougroup.com/search/label/MCS-014) (5) [MCS-015](https://mca.ignougroup.com/search/label/MCS-015) (6) [MCS-021](https://mca.ignougroup.com/search/label/MCS-021) (7) [MCS-022](https://mca.ignougroup.com/search/label/MCS-022) (18) [MCS-023](https://mca.ignougroup.com/search/label/MCS-023) (12) [MCS-024](https://mca.ignougroup.com/search/label/MCS-024) (24) [MCS-031](https://mca.ignougroup.com/search/label/MCS-031) (20) [MCS-032](https://mca.ignougroup.com/search/label/MCS-032) (26) [MCS-033](https://mca.ignougroup.com/search/label/MCS-033) (10) [MCS-034](https://mca.ignougroup.com/search/label/MCS-034) (6) [MCS-035](https://mca.ignougroup.com/search/label/MCS-035) (23) [MCS-041](https://mca.ignougroup.com/search/label/MCS-041) (7) [MCs-041 Solved Assignment](https://mca.ignougroup.com/search/label/MCs-041%20Solved%20Assignment) (4) [MCS-042](https://mca.ignougroup.com/search/label/MCS-042) (13) [MCS-043](https://mca.ignougroup.com/search/label/MCS-043) (16) [MCS-044](https://mca.ignougroup.com/search/label/MCS-044) (11) [MCS-052](https://mca.ignougroup.com/search/label/MCS-052) (2) [MCS-34](https://mca.ignougroup.com/search/label/MCS-34) (4) [MCS011](https://mca.ignougroup.com/search/label/MCS011) (16) [MCS012](https://mca.ignougroup.com/search/label/MCS012) (11) [MCS012 Parity bit](https://mca.ignougroup.com/search/label/MCS012%20Parity%20bit) (1) [MCS013](https://mca.ignougroup.com/search/label/MCS013) (17) [MCS014](https://mca.ignougroup.com/search/label/MCS014) (19) [MCS015](https://mca.ignougroup.com/search/label/MCS015) (15) [MCS016](https://mca.ignougroup.com/search/label/MCS016) (11) [mcs021](https://mca.ignougroup.com/search/label/mcs021) (18) [MCS022](https://mca.ignougroup.com/search/label/MCS022) (8) [MCs023](https://mca.ignougroup.com/search/label/MCs023) (2) [MCs024](https://mca.ignougroup.com/search/label/MCs024) (4) [MCS031](https://mca.ignougroup.com/search/label/MCS031) (28) [MCS032](https://mca.ignougroup.com/search/label/MCS032) (19) [MCS033](https://mca.ignougroup.com/search/label/MCS033) (5) [MCS034](https://mca.ignougroup.com/search/label/MCS034) (21) [mcs035](https://mca.ignougroup.com/search/label/mcs035) (8) [MCS041](https://mca.ignougroup.com/search/label/MCS041) (10) [MCS042](https://mca.ignougroup.com/search/label/MCS042) (1) [MCS043](https://mca.ignougroup.com/search/label/MCS043) (6) [MCS044](https://mca.ignougroup.com/search/label/MCS044) (10) [mcs045](https://mca.ignougroup.com/search/label/mcs045) (1) [MCS051](https://mca.ignougroup.com/search/label/MCS051) (18) [MCS052](https://mca.ignougroup.com/search/label/MCS052) (13) [MCS053](https://mca.ignougroup.com/search/label/MCS053) (11) [MCSE-003](https://mca.ignougroup.com/search/label/MCSE-003) (11) [MCSE-004](https://mca.ignougroup.com/search/label/MCSE-004) (11) [MCSE-011](https://mca.ignougroup.com/search/label/MCSE-011) (11) [mcse003](https://mca.ignougroup.com/search/label/mcse003) (1) [MCSL-016](https://mca.ignougroup.com/search/label/MCSL-016) (2) [MCSL-025](https://mca.ignougroup.com/search/label/MCSL-025) (7) [MCSL-036](https://mca.ignougroup.com/search/label/MCSL-036) (11) [MCSL-045](https://mca.ignougroup.com/search/label/MCSL-045) (4) [MCSL-054](https://mca.ignougroup.com/search/label/MCSL-054) (10) [MCSL017](https://mca.ignougroup.com/search/label/MCSL017) (11) [mcsl054](https://mca.ignougroup.com/search/label/mcsl054) (2) [MCSP-044](https://mca.ignougroup.com/search/label/MCSP-044) (1) [Mini Project](https://mca.ignougroup.com/search/label/Mini%20Project) (23) [network](https://mca.ignougroup.com/search/label/network) (1) [Networking](https://mca.ignougroup.com/search/label/Networking) (3) [Openmat results](https://mca.ignougroup.com/search/label/Openmat%20results) (1) [OS](https://mca.ignougroup.com/search/label/OS) (2) [Problem Solving and Programming](https://mca.ignougroup.com/search/label/Problem%20Solving%20and%20Programming) (1) [Project Analysis](https://mca.ignougroup.com/search/label/Project%20Analysis) (2) [Remote Access](https://mca.ignougroup.com/search/label/Remote%20Access) (1) [Security](https://mca.ignougroup.com/search/label/Security) (2) [Session](https://mca.ignougroup.com/search/label/Session) (4) [Shell Script](https://mca.ignougroup.com/search/label/Shell%20Script) (1) [Solution](https://mca.ignougroup.com/search/label/Solution) (1) [Solved](https://mca.ignougroup.com/search/label/Solved) (115) [Solved Assignments](https://mca.ignougroup.com/search/label/Solved%20Assignments) (32) [Solved Question paper](https://mca.ignougroup.com/search/label/Solved%20Question%20paper) (35) [Sort Notes](https://mca.ignougroup.com/search/label/Sort%20Notes) (1) [SRS](https://mca.ignougroup.com/search/label/SRS) (5) [TEE](https://mca.ignougroup.com/search/label/TEE) (17) [UML](https://mca.ignougroup.com/search/label/UML) (3) [unix](https://mca.ignougroup.com/search/label/unix) (1) [upper casem linux](https://mca.ignougroup.com/search/label/upper%20casem%20linux) (1) [Viva](https://mca.ignougroup.com/search/label/Viva) (2) [WindowsOS](https://mca.ignougroup.com/search/label/WindowsOS) (2) [ZONES](https://mca.ignougroup.com/search/label/ZONES) (1)
Powered by [Blogger](https://www.blogger.com/).
## Ad Blocker
Copyright © 2018 [MCA IGNOU GROUP](https://mca.ignougroup.com/) \| Crafted by [ignougroup.com](https://mca.ignougroup.com/2017/01/why-is-it-best-to-use-prime-number-as.html)
Looking for solved assignments?
Download now by filling this form.
### [Click to Download Now](https://goo.gl/forms/iQDvJAECGvCTNewK2) |
| Readable Markdown | **Question Detail:**
If I have a list of key values from 1 to 100 and I want to organize them in an array of 11 buckets, I've been taught to form a mod function
\$\$ H = k \\bmod \\ 11\$\$
Now all the values will be placed one after another in 9 rows. For example, in the first bucket there will be \$0, 11, 22 \\dots\$. In the second, there will be \$1, 12, 23 \\dots\$ etc.
Let's say I decided to be a bad boy and use a non-prime as my hashing function - take 12. Using the Hashing function
\$\$ H = k \\bmod \\ 12\$\$
would result in a hash table with values \$0, 12, 24 \\dots \$ in the first bucket, \$1, 13, 25 \\dots\$ etc. in the second and so on.
Essentially they are the same thing. I didn't reduce collisions and I didn't spread things out any better by using the prime number hash code and I can't see how it is ever beneficial.
###### Asked By : [CodyBugstein](http://cs.stackexchange.com/users/4348)
#### Answered By : [Mario Cervera](http://cs.stackexchange.com/users/57681/)
Consider the set of keys \$K=\\{0,1,...,100\\}\$ and a hash table where the number of buckets is \$m=12\$. Since \$3\$ is a factor of \$12\$, the keys that are multiples of \$3\$ will be hashed to buckets that are multiples of \$3\$:
- Keys \$\\{0,12,24,36,...\\}\$ will be hashed to bucket \$0\$.
- Keys \$\\{3,15,27,39,...\\}\$ will be hashed to bucket \$3\$.
- Keys \$\\{6,18,30,42,...\\}\$ will be hashed to bucket \$6\$.
- Keys \$\\{9,21,33,45,...\\}\$ will be hashed to bucket \$9\$.
If \$K\$ is uniformly distributed (i.e., every key in \$K\$ is equally likely to occur), then the choice of \$m\$ is not so critical. But, what happens if \$K\$ is not uniformly distributed? Imagine that the keys that are most likely to occur are the multiples of \$3\$. In this case, all of the buckets that are not multiples of \$3\$ will be empty with high probability (which is really bad in terms of hash table performance).
This situation is more common that it may seem. Imagine, for instance, that you are keeping track of objects based on where they are stored in memory. If your computer's word size is four bytes, then you will be hashing keys that are multiples of \$4\$. Needless to say that choosing \$m\$ to be a multiple of \$4\$ would be a terrible choice: you would have \$3m/4\$ buckets completely empty, and all of your keys colliding in the remaining \$m/4\$ buckets.
In general:
> Every key in \$K\$ that shares a common factor with the number of buckets \$m\$ will be hashed to a bucket that is a multiple of this factor.
Therefore, to minimize collisions, it is important to reduce the number of common factors between \$m\$ and the elements of \$K\$. How can this be achieved? By choosing \$m\$ to be a number that has very few factors: a **prime number**. |
| Shard | 32 (laksa) |
| Root Hash | 3437017450487322632 |
| Unparsed URL | com,ignougroup!mca,/2017/01/why-is-it-best-to-use-prime-number-as.html s443 |