Skip to main content

Menu

LEVEL 0
0/5 XP
HomeAboutTopicsPricingMy VaultStats

Categories

πŸ€– Artificial Intelligence
☁️ Cloud and Infrastructure
πŸ’Ύ Data and Databases
πŸ’Ό Professional Skills
🎯 Programming and Development
πŸ”’ Security and Networking
πŸ“š Specialized Topics
HomeAboutTopicsPricingMy VaultStats
LEVEL 0
0/5 XP
GitHub
Β© 2026 CheatGridβ„’. All rights reserved.
Privacy PolicyTerms of UseAboutContact

String Algorithms and Pattern Matching Cheat Sheet

String Algorithms and Pattern Matching Cheat Sheet

Back to Mathematics and Algorithms
Updated 2026-05-19
Next Topic: Topology Cheat Sheet

String algorithms and pattern matching form the backbone of text search engines, compilers, bioinformatics pipelines, and network intrusion detection systems. The central challenge is locating one or multiple patterns inside a potentially enormous text without inspecting every character at every position. Most efficient algorithms work by preprocessing the pattern β€” building jump tables, automata, or hash structures β€” so mismatches cause large skips rather than single-character retreats. A practitioner's most important decision is whether to match a single exact pattern (KMP or Boyer-Moore), multiple patterns simultaneously (Aho-Corasick), approximate patterns (Bitap/Levenshtein), or to index the text for repeated queries (suffix array or suffix automaton).


What This Cheat Sheet Covers

This topic spans 14 focused tables and 97 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.

Table 1 β€” Single-Pattern Exact Matching: Algorithm OverviewTable 2 β€” KMP: Prefix Function and LPS ArrayTable 3 β€” Z-AlgorithmTable 4 β€” Boyer-Moore: Heuristics and RulesTable 5 β€” Rabin-Karp and String HashingTable 6 β€” Aho-Corasick: Multi-Pattern MatchingTable 7 β€” Trie (Prefix Tree) OperationsTable 8 β€” Suffix Array and LCP ArrayTable 9 β€” Suffix Tree and Suffix AutomatonTable 10 β€” Palindrome Detection AlgorithmsTable 11 β€” Subsequence and Edit Distance AlgorithmsTable 12 β€” Anagram and Permutation DetectionTable 13 β€” String Compression and Canonical TransformsTable 14 β€” Approximate String Matching

Table 1 β€” Single-Pattern Exact Matching: Algorithm Overview

AlgorithmPreprocessing / ComplexityKey Idea & Notes
NaΓ―ve / Brute-Force
None Β· O(nm) worstSlide pattern one character at a time; compare each position. Simple but slow on repetitive text (e.g., aaaa…ab vs aab).
KMP (Knuth-Morris-Pratt)
O(m) prefix table Β· O(n+m) searchPrecompute failure function so mismatches jump without re-examining characters. Never backtracks in text.
Z-Algorithm
O(m+n) Z-arrayConcatenate P + $ + T; Z-array entry = length of longest match starting at that position. Match found when Z[i] == m.
Boyer-Moore
O(m + \sigma) tables Β· O(n/m) bestScans pattern right-to-left; two heuristics (bad-char + good-suffix) give sub-linear best case.

More in Mathematics and Algorithms

  • Statistics Fundamentals Cheat Sheet
  • Topology Cheat Sheet
  • Algebra Cheat Sheet
  • Combinatorics Cheat Sheet
  • Geometry Cheat Sheet
  • Mathematical Proof Techniques Cheat Sheet
View all 37 topics in Mathematics and Algorithms