WALCHAND INSTITUTE OF TECHNOLOGY, SOLAPUR
INFORMATION TECHNOLOGY
2021-22 SEMESTER - II
ASSIGNMENT - 8
Subject: Information Retrieval
Name: Ayush Pande Roll no: 74 Class: Final Year Btech IT
Title: Implementation of sequential searching using Brute Force Algorithm
Theory:
A brute-force algorithm for the string-matching problem is quite obvious: align
the pattern against the first m characters of the text and start matching the
corresponding pairs of characters from left to right until either all the m pairs of
the characters match (then the algorithm can stop) or a mismatching pair is
encountered. In the latter case, shift the pattern one position to the right and
resume the character comparisons, starting again with the first character of the
pattern and its counterpart in the text. Note that the last position in the text that
can still be a beginning of a matching substring is n − m (provided the text
positions are indexed from 0 to n − 1). Beyond that position, there are not enough
characters to match the entire pattern; hence, the algorithm need not make any
comparisons there.
Program Code:
#8
from tkinter import *
def Ass(string, sub_str):
for i in range(len(string) - len(sub_str) + 1):
index = i
for j in range(len(sub_str)):
if string[index] == sub_str[j]:
index += 1
else:
break
if index - i == len(sub_str):
return "Pattern found at index : "+str(i)
return "Pattern Not Found"
def mhello():
mtext = ment.get()
pat1 = pat.get()
output = Ass(mtext, pat1)
mlabel1 = Label(mgui, text=output).pack()
return
mgui = Tk()
ment = StringVar()
pat = StringVar()
mgui.geometry('450x450+500+300')
mgui.title('Brute Force')
mlabel = Label(mgui, text=' Brute force Algorithm :').pack()
mlabel2 = Label(mgui,bg="skyblue" ,text="ENTER THE TEXT").pack()
mentry = Entry(mgui, textvariable=ment).pack()
mlabel2 = Label(mgui, bg="skyblue",text="ENTER THE PATTERN").pack()
mentry1 = Entry(mgui, textvariable=pat).pack()
mbutton = Button(mgui, text="Find the pattern", command=mhello, fg='black', bg='skyblue').pack()
mgui.configure(bg="skyblue")
mgui.mainloop()
Screenshots/Output: