Skip to content

Commit a0e996c

Browse files
naivestringmatching.py
Naive Pattern Searching algo in python.
1 parent 2198b43 commit a0e996c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Strings/naivestringmatching.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def search(pat, txt):
2+
M = len(pat)
3+
N = len(txt)
4+
5+
# A loop to slide pat[] one by one
6+
for i in range(N - M + 1):
7+
j = 0
8+
9+
# For current index i, check
10+
# for pattern match
11+
while(j < M):
12+
if (txt[i + j] != pat[j]):
13+
break
14+
j += 1
15+
16+
if (j == M):
17+
print("Pattern found at index ", i)
18+
19+
# Driver Code
20+
if __name__ == '__main__':
21+
txt = "AABAACAADAABAAABAA"
22+
pat = "AABA"
23+
search(pat, txt)

0 commit comments

Comments
 (0)