Add compute_z_array Function with Unit Tests#930
Open
Simranstha045 wants to merge 2 commits intokeon:masterfrom
Open
Add compute_z_array Function with Unit Tests#930Simranstha045 wants to merge 2 commits intokeon:masterfrom
Simranstha045 wants to merge 2 commits intokeon:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description:
This PR introduces the implementation of the
compute_z_arrayfunction, which computes the Z-array for a given string in linear time, as well as comprehensive unit tests to verify its correctness.Description of
compute_z_arrayFunction:The
compute_z_arrayfunction calculates the Z-array for a string, where each element at indexirepresents the length of the longest substring starting from indexithat is also a prefix of the string.Key Features:
Use case:
The Z Algorithm is like a super-smart search tool that looks at parts of a string and tells you how much they match the beginning of the string. It's useful when you want to find patterns quickly, like searching for words in a long text, detecting DNA sequences, or even finding virus patterns in files. It does all this in a smart way, skipping unnecessary checks, so it's super fast!
Unit Tests for
compute_z_array:The following tests have been added to ensure robustness:
These unit tests ensure the function works as expected across a range of inputs, providing confidence in its correctness and edge-case handling.
All tests have been added under the
unittestframework to maintain consistency with the existing test suite.