File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ this algorithm tries to find the pattern from every position of
3+ the mainString if pattern is found from position i it add it to
4+ the answer and does the same for position i+1
5+
6+ Complexity : O(n*m)
7+ n=length of main string
8+ m=length of pattern string
9+ """
10+ def naivePatternSearch (mainString ,pattern ):
11+ patLen = len (pattern )
12+ strLen = len (mainString )
13+ position = []
14+ for i in range (strLen - patLen + 1 ):
15+ match_found = True
16+ for j in range (patLen ):
17+ if mainString [i + j ]!= pattern [j ]:
18+ match_found = False
19+ break
20+ if match_found :
21+ position .append (i )
22+ return position
23+
24+ mainString = "ABAAABCDBBABCDDEBCABC"
25+ pattern = "ABC"
26+ position = naivePatternSearch (mainString ,pattern )
27+ print ("Pattern found in position " )
28+ for x in position :
29+ print (x )
You can’t perform that action at this time.
0 commit comments