How can I calculate the probability of having no collision after inserting 2 elements. answer is 4/9, but I do not see it how it is 4/9
calculate the probability of having no collision when two elements are hashed h(x)=(x^2+1)mod3
457 Views Asked by user2149873 At
2
There are 2 best solutions below
0
AlcoJaguar
On
For a little background on why that pattern holds consider all the equivalency classes mod 3, that is { 0, 1, 2 }.
If x mod 3 = 0 then x^2 mod 3 = (x mod 3)(x mod 3) mod 3 = (0 * 0) mod 3 = 0 by distributive equivalency, so x^2 + 1 mod 3 = 1
If x mod 3 = 1 then x^2 mod 3 = (x mod 3)(x mod 3) mod 3 = (1 * 1) mod 3 = 1 , so x^2 + 1 mod 3 = 2
If x mod 3 = 2 then x^2 mod 3 = (x mod 3)(x mod 3) mod 3 = (2 * 2) mod 3 = 1 , so x^2 + 1 mod 3 = 2
It's still not 100% formal, and it's a clunky example by exhaustion, but it gives you an idea why this pattern holds for natural numbers union { 0 }. I also wish I was more familiar with math formatting on stack. Suppose it's time to hit up meta? :)
Related Questions in HASH
- Trouble validating md5 hashed password with randomly generated salt?
- Why k and l for LSH used for approximate nearest neighbours?
- PHP password_hash() / bcrypt
- Unique hash/index for time interval
- Order-independent Hash Algorithm
- git hard reset - what am I doing wrong?
- Java HashMap, hashCode() equals() - how to be consistent with multiple keys?
- Create hash from variables in loop
- Hashing integer coordinates of different sizes
- Xcode salting and hashing a password
- Is there a way to generate a Guid from a list of Guids?
- Path reconstruction with Hashing?
- Creating a Hash with keys from an array and empty arrays as the values
- How to read data from a different file without using YAML or JSON
- change value in hash using an array of keys in ruby
Related Questions in HASHTABLE
- Borrow mutable and immutable reference in the same block
- Loss of an element from hashtable using JDI
- csv parsing and manipulation using python
- java - how to create custom hashtable iterator?
- How to convert a string to a key for hash table
- How to use hash tables when amount of slots is unknown?
- Access a value in a generic array inside a generic class
- Why not use hash table with overflow area?
- Please share some insights on rehash method in java?
- Removing a node from a LinkedList (C#)
- Is there an extensible open address hash table?
- Valgrind newbie, can't seem to make it happy
- Are the "key" and "value" terms for hash tables and associative arrays used interchangeably?
- Why is the cost of a hash lookup O(1) when evaluating the hash function might take more time than that?
- How does hopscotch hashing actually work?
Related Questions in HASHSET
- Does java.util.HashSet not Adhere to its Specification?
- Optimizing list performance in C#
- Storing data in sorted manner in a HashSet
- Java: HashSet multiple types
- How to test collections in Junit (Java)
- Initialize method from HashSet
- Removing HashSet with Object
- Finding matching objects in Java
- how to not sort a HashSet values and allow duplicate?
- Why objects are not same added to hashset with same value, even hashCode and equals are overriden
- Calling a method from another class with the getMethod gives an error
- Viewbag , Printing data from hashset
- java: HashSet to show error message on inputing duplicate Integer values
- How Hashset avoids duplicates
- Implementing custom object for HashSet
Related Questions in GEOHASHING
- Using Kibana4 Tile Map with Geo-Points
- Solr faceting returning the average and the count
- Kibana 3 GeoJSON vs Kibana4 Geohash
- Cassandra CQL 3 - Prefix Select
- Standardizing GPX traces
- MongoDB $centerSphere vs Redis geospatial
- Solr - Using facets to sum documents based on variable precision geohashes
- Why Bounding Box Search executes too long?
- Elasticsearch how to use geohex_grid or geohash_grid return a full detail (or at lease get full detail when doc_count:1)
- Delete geographic point in dynamodb
- How to find if the point is within a bounding box in Tile38?
- Scalability of GeoHash Based proximity services
- firebase order by not working as expected
- Spatial data with mongodb or cassandra
- Looking for an JavaScript algorithm to match 2 persons within a given radius
Related Questions in UNIVERSAL-HASHING
- Universal hashing performs worse than modulo hashing, what is wrong?
- cmph Minimal perfect hashing
- Basics in Universal Hashing, how to ensure accessibility
- Hash a Range of Values
- How to generate 64 bit random numbers?
- understanding Universal hashing chapter on CLRS
- Ultra fast lookup in small sized container of 64-bit integer values using dynamic perfect hashing
- Is Universal family of hash functions only to prevent enemy attack?
- Unchange Data, hashing data
- Use of universal hashing
- Universal Hash Function Implementation for Strings in Java
- calculate the probability of having no collision when two elements are hashed h(x)=(x^2+1)mod3
- How to hide secret strings from application users in desktop installable application?
- Value of K hash functions so that probability of false positive is at most 1/n
- Pairwise independent hash functions in Java
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
I'm not so sure that this is an appropriate SO question, but here is my shot at the answer. It is by no means a legit mathematical proof, but it works.
For your function h(x) = (x^2+1)mod3, let's put it some sample values.
h(1) = (1+1)mod3 = 2mod3 = 2
h(2) = (4+1)mod3 = 5mod3 = 2
h(3) = (9+1)mod3 = 10mod3 = 1
h(4) = 17mod3 = 2
h(5) = 26mod3 = 2
h(6) = 37mod3 = 1
This pattern will continue due to the nature of the function (squaring and adding 1).
So, we have a (2/3) chance of an input to our function evaluating to 2, and a (1/3) chance that it will evaluate to a 1.
If we insert two elements, the probability that we HAVE a collision is the probability of both inputs evaluating to 2 plus the probability of both evaluating to 1. This is:
(2/3)(2/3) + (1/3)(1/3) = 4/9 + 1/9 = 5/9
Thus, the probability that any two inputs WILL NOT have a collision is 1 - (5/9)
or 4/9.