0% found this document useful (0 votes)
1 views2 pages

String Matching

The document presents a practical assignment for the course SEIT3211, focusing on finding the index of the first occurrence of a substring within a string using C++. It includes a code implementation of the algorithm and specifies conditions for handling empty or longer needle cases. A submission link to an online platform is also provided.

Uploaded by

23se02ce030
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

String Matching

The document presents a practical assignment for the course SEIT3211, focusing on finding the index of the first occurrence of a substring within a string using C++. It includes a code implementation of the algorithm and specifies conditions for handling empty or longer needle cases. A submission link to an online platform is also provided.

Uploaded by

23se02ce030
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SEIT3211 – Design and Analysis of Algorithms 23SE02CE030

PRACTICAL-11

AIM: Find the index of First Occurrence in the String


CODE:

#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
int strStr(string haystack, string needle) {
int n = [Link]();
int m = [Link]();

if(m == 0) return 0; // empty needle case


if(m > n) return -1; // needle longer than haystack

for(int i = 0; i <= n - m; ++i){


auto itH = [Link]() + i;
auto itN = [Link]();
int j = 0;

while(j < m && *(itH + j) == *(itN + j)){


j++;
}

if(j == m) return i; // found full match


}
return -1;
}
};

OUTPUT:
SEIT3211 – Design and Analysis of Algorithms 23SE02CE030

Submission Link :

[Link]
string/submissions/1780409127

You might also like