0PricingLogin
Competitive Programming Academy · Lesson

Z-Function for Pattern Search

Match prefixes across the string.

Another Matching Tool

The Z-function is a clean alternative to KMP for pattern search. Many find it easier to reason about. ✨

What z[i] Means

For each index, z[i] is the length of the longest substring starting at i that also matches a prefix of the whole string.

All lessons in this course

  1. KMP Prefix Function
  2. Polynomial String Hashing
  3. Z-Function for Pattern Search
  4. Tries for Prefix Lookups
← Back to Competitive Programming Academy