Skip to content
This repository has been archived by the owner on Oct 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #33 from Nandinisaagar/main
Browse files Browse the repository at this point in the history
Naive Pattern Searching Algorithm[Added a code in DSA folder] (Issue #5)
  • Loading branch information
rohansaini886 authored Sep 30, 2022
2 parents 3be944a + f0b6b4f commit a345edb
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
Binary file added Data Structure And Algorithms/LIS
Binary file not shown.
33 changes: 33 additions & 0 deletions Data Structure And Algorithms/LIS.cpp
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 Data Structure And Algorithms/LIS.dSYM/Contents/Info.plist
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.
30 changes: 30 additions & 0 deletions Data Structure And Algorithms/NaivePatternSearchingAlgo.c
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;
}

0 comments on commit a345edb

Please sign in to comment.