Pattern Matching
Learn Pattern Matching (Strings, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
The Naive Pattern Matching Approach Given a text of length n and a pattern of length m, find every position where the pattern occurs. The naive approach tries every starting position and compares character by character - O(n·m) worst case (e.g. text "aaaa...a", pattern "aaa...b").