iodump01 / CodeQuest

0 stars 6 forks source link

Tuesday - Tricks X Algorithms #14

Open Sejaa24 opened 1 year ago

SiyedRizvee commented 1 year ago

Twitter:

KMP Algorithm

The key of KMP is to build a look up table that records the match result of prefix and postfix. Value in the table means the max len of matching substring that exists in both prefix and postfix. In the prefix this substring should starts from 0, while in the postfix this substring should ends at current index.

For example, now we have a string "ababc"

The KMP table will look like this:

a b a b c 0 0 1 2 0

LinkedIn:

KMP Algorithm

The key of KMP is to build a look up table that records the match result of prefix and postfix. Value in the table means the max len of matching substring that exists in both prefix and postfix. In the prefix this substring should starts from 0, while in the postfix this substring should ends at current index.

For example, now we have a string "ababc"

The KMP table will look like this:

a b a b c 0 0 1 2 0

Instagram:

KMP Algorithm

The key of KMP is to build a look up table that records the match result of prefix and postfix. Value in the table means the max len of matching substring that exists in both prefix and postfix. In the prefix this substring should starts from 0, while in the postfix this substring should ends at current index.

For example, now we have a string "ababc"

The KMP table will look like this:

a b a b c 0 0 1 2 0

Image