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
458 views Asked by user2149873 At
2
There are 2 answers
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
- How can py tuple implicit cast to int?
- How to properly set hashes in script-src CSP policy header?
- Algorithm for finding the largest common substring for n strings using Rabin-Karp function
- Lua: is there a need to use hash of string as a key in lua tables
- When the key values are the same, the memory limit is exceeded when making a hash join
- Short for creating an array of hashes in powershell malfunction?
- LC347: Top K Frequent Elements; final result returns an extra element in list/array
- Hashing vertices of a Graph in C
- Is there a limit on the message size for SHA3?
- When hashing an API key, should I hash the suffix / prefix as well?
- Cmake error : Configuring incomplete, errors occurred
- murmur3 hashing function in postgres
- Hashing the password if it is not hashed in django
- Order of a set in Python
- Comparing the hash of a file, containing a list of hashes of multiple files instead of each file, is it good?
Related Questions in HASHTABLE
- Hashing vertices of a Graph in C
- The difference between set definitions in Python
- Order of a set in Python
- Why is fast lookup possible for dict.items()?
- Radix tree vs Hashtable
- Hashtable lookup time confusing if hash function is not constant
- Hash Table creation runtime complexity
- Powershell script no longer working, error "The assignment expression is not valid. "
- Why python3 dict's get method O(1) time while under the hood it is aclually O(n)?
- How to benchmark/compare Hlist and rbtree?
- Powershell I can not figure out how to process several hash-tables to desired output with help of inlayed foreach cycles
- Is there a way to call libcuckoo's cuckoo_hash_map with keys only (C++)?
- Problem with not existing element in Hash Table in C
- Memory leak in C: free a hashtable
- My program just stopped printing in the outputFile after I add some changes
Related Questions in HASHSET
- HashSet: Why valueType.Equals(Object) is so slow
- Can't print simple HashSet<int[]> elements in java
- Fastest way to check if a GUID of set size has been encountered before
- Get an Array from HashSet in c# with operator [..]
- Dictionary.ContainsKey() vs. large arrays used for lookup, any alternative?
- C# Grabbing subset of table based off a Hashset if Ints
- Code using ArrayList and HashSet in Java i too slow
- Why is my HashSet being serialized incorrectly in ORMLite? It appears to be serialized with the wrong size
- Rust ownership for pushing to a vector whose members are referenced
- Problem with altering property's value of an object that is inside a HashSet in JAVA
- Efficient way to check if a ReadOnlyMemory<char> contains in a Hashset in C#
- Difference between a HashSet in C# and HashSet in Java. Any alternatives
- CSVHelper doesn't store HashSet fields
- Linear probing hash set - efficient way to know if value is already inserted, just not in its hashed index
- Using clear() vs copy() in a hashset
Related Questions in GEOHASHING
- Get longitude and latitude for the corners of a geohash
- Are geohash tiles the same size anywhere on the globe?
- Error loading data - google sheet app script, javascript, geohash
- Scalability of GeoHash Based proximity services
- firebase order by not working as expected
- How to find if the point is within a bounding box in Tile38?
- Delete geographic point in dynamodb
- Elasticsearch how to use geohex_grid or geohash_grid return a full detail (or at lease get full detail when doc_count:1)
- GeoHashUtils Library not working as expected
- Find N closest points with geohash
- Location based GeoFire queries . How to load the documents in batches
- Visualize Geohash after Drawing it on same map (Streamlit Folium)
- Is there a table for every country's geohash codes?
- Geospatial rolling average from geohashes on BigQuery
- Tinder-like search based on distance in Flutter - Most efficient way?
Related Questions in UNIVERSAL-HASHING
- How to hide secret strings from application users in desktop installable application?
- Ultra fast lookup in small sized container of 64-bit integer values using dynamic perfect hashing
- Easily Memorable Hash (what 3 words)
- Universal Hash Function Implementation for Strings in Java
- Unchange Data, hashing data
- Value of K hash functions so that probability of false positive is at most 1/n
- Use of universal hashing
- Describe an Explicit Universal Hash Function Family
- Is it a secure method to generate token?
- Pairwise independent hash functions in Java
- Using C++ class as mere bit container
- cmph Minimal perfect hashing
- Universal hashing performs worse than modulo hashing, what is wrong?
- How can I check file differences in JavaScript?
- Is Universal family of hash functions only to prevent enemy attack?
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?
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)
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.