This repository has been archived by the owner on Oct 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from Nandinisaagar/main
Naive Pattern Searching Algorithm[Added a code in DSA folder] (Issue #5)
- Loading branch information
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,33 @@ | ||
// This code is contributed by Nandinisaagar | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int lis(int arr[], int n) | ||
{ | ||
int *lis, i, j, max = 0; | ||
lis = (int*)malloc(sizeof(int) * n); | ||
|
||
for (i = 0; i < n; i++) | ||
lis[i] = 1; | ||
|
||
for (i = 1; i < n; i++) | ||
for (j = 0; j < i; j++) | ||
if (arr[i] > arr[j] && lis[i] < lis[j] + 1) | ||
lis[i] = lis[j] + 1; | ||
|
||
for (i = 0; i < n; i++) | ||
if (max < lis[i]) | ||
max = lis[i]; | ||
|
||
free(lis); | ||
|
||
return max; | ||
} | ||
int main() | ||
{ | ||
int arr[] = { 10, 22, 9, 33, 21, 50, 41, 60 }; | ||
int n = sizeof(arr) / sizeof(arr[0]); | ||
cout <<"Length of lis is "<< lis(arr, n); | ||
return 0; | ||
} | ||
|
20 changes: 20 additions & 0 deletions
20
Data Structure And Algorithms/LIS.dSYM/Contents/Info.plist
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>English</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.apple.xcode.dsym.LIS</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundlePackageType</key> | ||
<string>dSYM</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
</dict> | ||
</plist> |
Binary file not shown.
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,30 @@ | ||
// C program for Naive Pattern Searching algorithm | ||
// This code is contributed by Nandinisaagar | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
void search(char* pat, char* txt) | ||
{ | ||
int M = strlen(pat); | ||
int N = strlen(txt); | ||
|
||
for (int i = 0; i <= N - M; i++) { | ||
int j; | ||
|
||
for (j = 0; j < M; j++) | ||
if (txt[i + j] != pat[j]) | ||
break; | ||
|
||
if (j== M) | ||
printf("Pattern found at index %d \n", i); | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
char txt[] = "AABAACAADAABAAABAA"; | ||
char pat[] = "AABA"; | ||
|
||
search(pat, txt); | ||
return 0; | ||
} |