Add compute_z_array Function with Unit Tests #930
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_array
function, 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_array
Function:The
compute_z_array
function calculates the Z-array for a string, where each element at indexi
represents the length of the longest substring starting from indexi
that 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
unittest
framework to maintain consistency with the existing test suite.