Data structure (XI) string

A, ADT

definition

 

 the term

 

ADT

 

 b1 string matching

 

 

Algorithm Evaluation

 

 

b2 brute force match

 

 A version

 

 Version 2

 

 

the complexity

 

 

 

 

 

 

 

 

c1KMP algorithms: from memory to predict the force

Brute force, why inefficient

 

 

Many do not have to compare

 

 

Invariance

 

 

As long as memory is strong enough

 

 

Memory into force foreseen

 

c2KMP algorithms: a lookup table

Determined in advance t

 

 algorithm

 

 

Examples

Pattern string corresponding lookup tables below, the antepenultimate characters rank j = 7, the lookup table is next 3

 

 The main string, if you turn to this entry play a role, indicating that the current round than in the previous seven characters are successful

 

 That case scenario is as follows, i.e. l ​​character pattern string, a text string is not character alignment failure l

 

Than before to take a snapshot of the mode string

 

 KMP algorithm performed manually, current j = 7, the character string in the pointing mode L, next, KMP corresponding to that taken out a next [7} in a lookup table, and use it to update j, this items is 3 , will use the next rank character 3, which is substituted with L n, and continue to be aligned with the previous character in the text string mismatch, like this:

 

 

Snapshot mode make another one for the string:

 

 

 Before and after the two snapshots, four moving pattern string of characters to the right, three alignment positions excluding the KMP

 

 

c3 KMP algorithm: Next understood that [] table

 

Fast right from match =

With the necessary conditions, negative alignment position

 

 

Right from the longest match = Fast + avoid rollback

 

Next[0]==1

 

 Clever use of the Sentinel, the code can be simplified, unified understanding

 

 

c4 KMP algorithm: Next structure [] table

Recurrence

 

 

achieve

 

 

c5 KMP algorithm: apportionment analysis

 

 

c6 KMP algorithm: further improvements

Counterexample

 

 Improve

 

 

Failures: Brute-force

Failures: KMP

 

Multiple characters on multiple characters

d1 BM algorithm: bad character

 

Treat lesson

More attention to lessons, to make it appear earlier, who earlier emergence of more

 

After former light heavy

 

Begin with the End

 

 Bad-Character

 

 

BC configuration [] table

 

 

Best case

 

Worst case

 Make good use of the lessons, there is no experience to good use

 

 

e1 BM_GS algorithm: Good suffix

Experience matched suffix =

 

 

good suffix shift

 

 

Examples

 

 

e2 BM_GS algorithms: construction gs table

MS[]->ss[]

 

 

 

ss[]->gs[]

 

 

 Construction ss []

 

 

 

 

e3 BM_GS algorithms: overall performance

performance

 

 

 

 

Overview

 

 

 

f1 Karp-Rabin algorithm: that is, the number of strings

 

 All things are numbers

 

 

 

 

Also a number of string

 

 

f2 Karp-Rabin algorithm: hash

Digital overflow

 

 

Hash compression

 

 Hash collision

 

 快速指纹计算

 

Guess you like

Origin www.cnblogs.com/aidata/p/11584445.html