Professional Documents
Culture Documents
3
Student Name: Shaurav Suman Kumar UID: 19BCS2201
Branch: BE-CSE Section/Group: 8/C
Semester: 5th Date: 17-11-2021
Subject Name: Design and Analysis of Algorithms Lab Subject Code: CSP-309
Aim: Code and analyze to find all occurrence of pattern P in a given string S.
Algorithm:-
Naïve pattern searching algorithm is used to perform this experiment.
• Slide the pattern over text one by one and check for a match.
• If a match is found, then slides by 1 again to check for subsequent matches.
Code:-
#include <stdio.h>
#include <string.h>
Complexities:-
The best case occurs when the first character of the pattern is not present in text at all. The
number of comparisons in best case is O(n).
The worst case of Naive Pattern Searching occurs in following scenarios.
Learning Outcomes:-