-
Notifications
You must be signed in to change notification settings - Fork 19
Description
So, what is it about?
📌 Description
Add a visualizer for the Rabin-Karp algorithm, a string-matching algorithm that uses hashing to find a pattern in a text.
This visualizer will demonstrate the "rolling hash" technique, which is the core of the algorithm's efficiency.
✅ Expected Behavior
Input Panel: Allow users to enter a Text string and a Pattern string.
Visualization Area:
Display the Text and Pattern strings clearly.
Show a "sliding window" over the text that matches the pattern's length.
Display the numeric hash value for the Pattern (patternHash).
Display the numeric hash value for the current window (windowHash).
Animation Logic:
Animate the calculation of the patternHash.
Animate the calculation of the hash for the first window of the text.
For each step, animate the "rolling" of the hash:
Highlight the character being removed from the window's left.
Highlight the character being added to the window's right.
Show the windowHash value updating.
When patternHash === windowHash, highlight the window (e.g., in yellow) for a "Hash Match".
Animate the character-by-character check to confirm the match.
If it fails, mark it as a "Spurious Hit" (e.g., red) and continue.
If it succeeds, mark it as a "Pattern Found" (e.g., green).
Explanation Panel: Show a human-readable log of the actions.
"Calculating initial hash for pattern 'ABC' = 6578."
"Rolling... Removing 'A' (hash 100), Adding 'D' (hash 103). New hash: 7890."
"Hash Match Found! patternHash (6578) === windowHash (6578). Verifying..."
"Spurious Hit! Characters do not match. Resuming search."
Control Panel: Include Play/Pause, Reset, Step-through, and Speed controls.
🧩 Why This Is Needed
Rabin-Karp is a classic and practical string-matching algorithm.
It's the perfect way to visualize the concept of hashing and its trade-offs.
It clearly demonstrates the "rolling hash" technique (a form of dynamic calculation).
It introduces the important concept of a "spurious hit" and how probabilistic algorithms handle them.
Code of Conduct
- I agree to follow this project's Code of Conduct