Skip to content

Commit e5ff34e

Browse files
author
Hamid Gasmi
committed
Suffix Array Pattern Matching algorithm is added
1 parent 1f0bd3a commit e5ff34e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

README.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -3588,6 +3588,30 @@
35883588
Pos(A3) = Pos($1) + 1 = 8 = 0
35893589
Pos(G1) = Pos(A3) + 1 = 1
35903590
Pos(A2) = Pos(G1) + 1 = 2
3591+
- SuffixArray_PatternMatching(Text, Pattern, SuffixArray):
3592+
minIndex = 0
3593+
maxIndex = |Text|
3594+
While mindIndex < maxIndex:
3595+
midIndex = (minIndex + maxIndex) // 2
3596+
if Pattern > Suffix of Text starting at position SuffixArray(midIndex):
3597+
minIndex = midIndex + 1
3598+
else:
3599+
maxIndex = midIndex
3600+
start = minIndex
3601+
3602+
maxIndex = |Text|
3603+
While mindIndex < maxIndex:
3604+
midIndex = (minIndex + maxIndex) // 2
3605+
if Pattern < Suffix of Text starting at position SuffixArray(midIndex):
3606+
maxIndex = midIndex
3607+
else:
3608+
minIndex = midIndex + 1
3609+
end = maxIndex
3610+
3611+
if start > end:
3612+
return "Pattern does not appear in Text"
3613+
else:
3614+
return (start, end)
35913615
- Space Complexity: ~4/K x |*Text*| space with Manber-Myers algorithm
35923616
- Matching Pattern running Time:
35933617
- It's multiplied by x *K*
@@ -3602,7 +3626,7 @@
36023626
- Mismatch # Mismatch # Mismatch # Array Suffix
36033627
$1------A1 $1------A1 $1------A1 7
36043628
t ->A1------T1 1 A1------T1 A1------T1 6_
3605-
A2------G1 1 A2------G1 t->A2------G1 0 2 \
3629+
A2------G1 1 A2------G1 t ->A2------G1 0 2 \
36063630
A3------$1 1 A3------$1 A3------$1 1 0 | Approx. Match
36073631
b ->A4------C1 0 A4------C1 b ->A4------C1 1 4_ / at {0, 2, 4}
36083632
C1------A2 t ->C1------A2 0 C1------A2 3

0 commit comments

Comments
 (0)