String Matching Using Brute Force Method
Session No.: 11
Course Name: Design and analysis of algorithm
Course Code: R1UC407B
Instructor Name: Pradeep Chauhan
Duration: 50 Min.
Date of Conduction of Class:
Galgotias University 1
Review of the key concepts:
Analysis of Time Complexity Recursive algorithm using Master Theorem
method.
Galgotias University 2
How will we solve recurrence relation using Master
method?
Galgotias University 3
Learning Outcome:Student will be able to
Apply the Brute Force
Approach for String Matching
Galgotias University 4
1 Introduction
2 Concept and definition
Session
3 Activity (scenario based)
Outline
4 Reflection learning activity
5 Conclusion
6 Feedback
Galgotias University 5
Brute Force approach for String Matching:
static void patfind(String text,String pat)
{
int tl=text.length();
int pl=pat.length();
int i=0,j=0;
for(i=0;i<=tl-pl;i++)
{
for(j=0;j<pl;j++)
{
if(pat.charAt(j)!=text.charAt(i+j))
break;
}
if(j==pl)
System.out.print(i+" ");
}
}
Galgotias University 6
Activity-1: Think Pair Share (10 minutes)
Find time complexity of Brute Force approach for String Matching.
Galgotias University 7
Complexity of Brute Force Approach
for String Matching:
O(N*M) Where N is length of Text String and M is
length of Pattern String.
Galgotias University 8
Learning Outcome : Student can now
Apply the Brute Force
Approach for String Matching
Galgotias University 9
Post session activities
MCQ Based Quiz on LMS.
Galgotias University 10
In the next session, Rabin Karp Algorithm
for string matching will be discussed in
detail.
Galgotias University 11
Review and Reflection
from students
Galgotias University 12