Home Week-9

 

PDSA - Week 12 (As Extra Content)

String matching

Searching for a pattern is a fundamental problem when dealing with text

Example

Formally

Brute force approach

Nested scan from left to right in t

Output

Complexity

O(nm)

 

Nested scan from right to left

Output

Complexity

O(nm)

 

Speeding up the brute force algorithm

 

Boyer-Moore Algorithm

Algorithm

Implementation

Output

Complexity

Worst case remains O(nm)

If t = aaa...a, p = baaa

 

Rabin-Karp Algorithm

Implementation

Output

Analysis

 

Rabin Karp Implementation for strings

Output

 

 

Knuth-Morris-Pratt algorithm

Computing the fail function

Implementation of fail function

Output

Complexity

O(n)

 

Implementation of KMP algorithm

Output

Analysis

 

Tries

Implementation of Tries

Output

Analysis

 

Suffix Tries

Implementation of suffix tries

Output

 

Regular expression

use lecture's slides