String Matching and Computational Limits

26. String Matching and Computational Limits#

A text search can reuse a proved prefix match, while an optimization search may still face rapidly growing work. This chapter connects direct matching and KMP to computational growth, exact witnesses, heuristics, and approximation guarantees. The three core sections emphasize result contracts and evidence; this chapter remains optional for the College of Business pathway.

  • String matching: Searching for a pattern inside a larger text.

  • Prefix reuse: Retaining a proven matching suffix instead of restarting every comparison.

  • Computational limit: A point where exact brute-force computation grows too quickly to be practical.

  • Approximation: A method with a proved quality bound relative to the optimum under stated assumptions.

The first lesson extends shortest-path search to networks with negative edges and shows how to verify a distance report.

Chapter Video

9.1 Knuth-Morris-Pratt KMP String Matching Algorithm (18:55) by Abdul Bari.

Hosted on YouTube; property of its original creator, embedded here for educational reference only.

This introduction visualizes prefix reuse in KMP. Apply the precise C# text-unit and result contracts from Sections 26.1 and 26.2.

The retained graph video below is prerequisite review for the service-network assignments, rather than the main string-matching introduction.

Algorithms Course - Graph Theory Tutorial from a Google Engineer (6:44:39) by freeCodeCamp.org.

Hosted on YouTube; property of its original creator, embedded here for educational reference only.

Learning Objectives

By the end of this chapter, you will be able to:

  1. Implement direct and prepared-prefix matching under explicit ordinal, overlap, and empty-pattern contracts.

  2. Justify prefix fallback and linear comparison bounds, including preparation and output costs.

  3. Validate exact and heuristic coverage witnesses and distinguish feasibility, optimality, and proved approximation guarantees.

  4. Compare complete workloads and exact growth models without confusing measurements with general lower-bound proofs; distinguish decision certificates, optimization, and numeric-target costs.

  5. Reuse Chapter 20’s BFS, DFS, and component contracts to verify a service-network feature, and distinguish this prerequisite synthesis from the new string-matching and limits algorithms.

  6. Choose a shortest-path algorithm for the stated edge costs and verify a proposed distance report with a certificate.

Chapter Flow

For traversal verification, return to Chapter 20; for hop-versus-cost objectives, review Chapter 24.

Assignment preparation: the lab and homework also synthesize earlier graph work. Review Breadth-First Search and Paths and Depth-First Search and Components before the network tasks. The visible starter cells include the GraphWalk support used for client checks, so you do not need to reveal an answer to obtain that type. The preview focuses on this chapter’s new matching and limits concepts.

Glossary

#

Term

Explanation

1

String matching

Finding whether and where a pattern occurs in a text.

2

Pattern

The string or structure being searched for.

3

Text

The larger string being searched.

4

Prefix table

A table that records reusable information about matching prefixes in a pattern.

5

Intractable problem

A problem considered computationally difficult in a stated model; one slow implementation alone does not prove this classification.

6

Approximation

An algorithm with a proved objective bound relative to the optimum under stated assumptions.

7

Limit

A constraint, such as time or memory, that shapes algorithm choice.

8

Border

A proper pattern prefix that is also a suffix of the matched segment.

9

Ordinal match

Equality of UTF-16 code units without culture rules, case folding, or normalization.

10

Heuristic

A practical method used without an optimality or approximation guarantee established here.

11

KMP

Knuth-Morris-Pratt matching, which uses a prefix table to avoid restarting proven text comparisons.

12

Witness

A concrete candidate whose stated feasibility and objective value can be checked.

13

Exact search

A search intended to establish the required exact answer under its stated contract.

14

Resource limit

A bound on work or storage that may stop a search before it establishes an answer.

15

Decision problem

A problem whose output is yes or no, such as whether at most k teams cover all skills.

16

P

Decision problems solvable in polynomial time in encoded input length.

17

NP

Decision problems whose yes instances admit polynomial-length certificates checkable in polynomial time.

18

NP-complete

Decision problems in NP to which every NP problem reduces in polynomial time.

19

NP-hard optimization

An optimization task at least as hard as the associated NP-complete decision task, such as minimum set cover.

20

Pseudo-polynomial

Polynomial in a numeric input value, which may be exponential in its encoded length.

21

Incumbent

A verified feasible solution retained as the current candidate during optimization.

Lecture Slides

Chapter 26 Slides