Blog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2025 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Algorithms
Algorithmshard

KMP vs naive substring search — what’s the core idea of KMP?

Tags
#kmp#string-search#pattern-matching
Back to categoryPractice quiz

Answer

KMP precomputes a prefix function (LPS) so when a mismatch happens, it shifts the pattern without re-checking characters. This makes search O(n+m) instead of O(n·m).

Related questions

Algorithms
KMP string search: how does the LPS/prefix table avoid re-checking characters?
#kmp#string#pattern-matching
Data Structures
What is a suffix array (or suffix tree) used for?
#strings#suffix-array#suffix-tree