-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Spectrum-CETB:main' into main
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
void search(char pat[100], char txt[100]) | ||
{ | ||
int pat_len = strlen(pat); | ||
int txt_len = strlen(txt); | ||
int sum, n = 0; | ||
for (int i = 0; i < txt_len; i++) | ||
{ | ||
if (txt[i] == pat[0]) | ||
{ | ||
sum = 0; | ||
for (int j = 0; j < (pat_len - 1); j++) | ||
{ | ||
if (txt[i + j + 1] == pat[j + 1]) | ||
{ | ||
sum++; | ||
} | ||
} | ||
|
||
if (sum == 2) | ||
{ | ||
n++; | ||
printf("Pattern found at index %d\n",i); | ||
} | ||
} | ||
} | ||
} | ||
int main() | ||
{ | ||
char pat[100]; | ||
char txt[100]; | ||
printf("Enter the pattern\n"); | ||
gets(pat); | ||
printf("Enter the text\n"); | ||
gets(txt); | ||
search(pat, txt); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# <Title of the Problem> | ||
Pattern Finder | ||
|
||
# Problem Explanation 🚀 | ||
Given a text txt[0. . .n-1] and a pattern pat[0. . .m-1]. | ||
|
||
Write a function search(char pat[], char txt[]) that prints all occurrences of pat[] in txt[].. | ||
|
||
# Your logic 🤯 | ||
* Approach: Created two arrays to hold the two strings and compared the array one by one and get the index | ||
* Own test cases if any | ||
* Code Structure and Libraries used | ||
|
||
# Time Complexity and Space Complexity | ||
```cpp | ||
Example | ||
|
||
Time Complexity -> O(n^2) | ||
Space Complexity -> O(1) | ||
|
||
``` |