Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Z-function and its calculation.cpp #46

Merged
merged 1 commit into from Oct 8, 2022

Conversation

Lonewolf0502
Copy link
Contributor

Z-function and its calculation

Suppose we are given a string
of length . The Z-function for this string is an array of length where the -th element is equal to the greatest number of characters starting from the position that coincide with the first characters In other words,
is the length of the longest string that is, at the same time, a prefix of and a prefix of the suffix of starting Note. In this article, to avoid ambiguity, we assume -based indexes; that is: the first character of has index and the last one has index The first element of Z-function, is generally not well defined. In this article we will assume it is zero (although it doesn't change anything in the algorithm implementation). This article presents an algorithm for calculating the Z-function in time, as well as various of its applications.

Z-function and its calculation

Suppose we are given a string
of length . The Z-function for this string is an array of length where the -th element is equal to the greatest number of characters starting from the position that coincide with the first characters 
In other words,
is the length of the longest string that is, at the same time, a prefix of and a prefix of the suffix of starting 
Note. In this article, to avoid ambiguity, we assume
-based indexes; that is: the first character of has index and the last one has index
The first element of Z-function, is generally not well defined. In this article we will assume it is zero (although it doesn't change anything in the algorithm implementation).
This article presents an algorithm for calculating the Z-function in
time, as well as various of its applications.
@markandey007 markandey007 merged commit e91ce1e into markandey007:main Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants