kounkou / Hedgehog

Hedgehog is an interview preparation tool using space repetition to help master algorithms and data structures
http://kounkou.github.io/hedgehog-web
MIT License
3 stars 0 forks source link

Hashing questionID to produce a color for a question generates color collisions for the eye #118

Open kounkou opened 3 days ago

kounkou commented 3 days ago

Description

So I have a hard problem... Or I think I do... 🥲 I am trying to generate colors for each questions for the Stats graph. It turns out, the solution I wanted to go with is to hash the questionID, like : BFS, or DFS etc... and then generate a color based on it. But I am getting collisions (as expected)

Acceptance criteria

Example of collisions

notice how Merge Int., bfs it., 'Factorial`, ... have collisions when I hash the questionId to a 16 bits integer.

Screenshot 2024-11-11 at 4 16 00 PM

Here are collisions on a 32 bit integer hashed number binary search and Insert int. ...

Screenshot 2024-11-11 at 4 17 54 PM

Debuging infos

To confirm those are color collisions I checked what's the hue produced for 2 questionIds resulting in similar colors. Those really are collisions for the human eye. Notice the 4 points gap between bother hues

Here is the eye collision seen for Topological sort and Meeting rooms

Screenshot 2024-11-11 at 8 03 17 PM
qml: ---> questionId:  Topological sort
hash:  254168623
hue:  343

qml: ---> questionId:  Meeting rooms
hash:  780882099
hue:  339
kounkou commented 3 days ago

This post is really interesting!

https://stackoverflow.com/questions/1168260/algorithm-for-generating-unique-colors