From 79b85c3d4f3d01ea8e0eb8f41652a554974b1cf1 Mon Sep 17 00:00:00 2001 From: KavishanSukumar Date: Wed, 20 Oct 2021 16:54:26 +0530 Subject: [PATCH 1/3] Adding Boyer-MooreHorspool Algorithm for string matching in python language --- .../Boyer-MooreHorspoolAlgorithm.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 String Algorithms/String Matching/Boyer-MooreHorspoolAlgorithm.py diff --git a/String Algorithms/String Matching/Boyer-MooreHorspoolAlgorithm.py b/String Algorithms/String Matching/Boyer-MooreHorspoolAlgorithm.py new file mode 100644 index 0000000..54b9913 --- /dev/null +++ b/String Algorithms/String Matching/Boyer-MooreHorspoolAlgorithm.py @@ -0,0 +1,48 @@ +import os + +CHAR=256 + +def badCharacterTable(pattern): + length=len(pattern) + badchar=[length]*CHAR + + for i in range(length-1): + badchar[ord(pattern[i])]=length-i + + return badchar + +def stringSearch(text,pattern): + textlen=len(text) + patternlen=len(pattern) + badchar=badCharacterTable(pattern) + occurance=[] + position=0 + if(text=="" or pattern==""): + print("Text:"+text+"\nPattern:"+pattern+"\nTotal Number matched:"+str(len(occurance))+"\nPositions matched:"+', '.join(occurance)) + return + + while(position<=(textlen-patternlen)): + j=patternlen-1 + while(j>=0 and (text[position+j]==pattern[j] or pattern[j]=='_')): + j=j-1 + + if(j==-1): + occurance.append(str(position+1)) + position=position+1 + else: + position=position+ max(1,j-badchar[ord(text[position+j])]) + print("Text:"+text+"\nPattern:"+pattern+"\nTotal Number matched:"+str(len(occurance))+"\nPositions matched:"+', '.join(occurance)) + +def main(): + while (1): + text=input("Enter a sample text:") + pattern=input("Enter a pattern:") + stringSearch(text,pattern) + print("\nEnter 1 to test Continue\nEnter 0 to EXIT") + n=input("Enter your choise: ") + if(n=='0'): + return + + +if __name__=="__main__": + main() From cdaee5bda6742c8b6051271964a038fd627889e1 Mon Sep 17 00:00:00 2001 From: KavishanSukumar Date: Wed, 20 Oct 2021 17:31:08 +0530 Subject: [PATCH 2/3] Adding undirected graph using Cpp langague --- .../UndirectedGraphMatrix.cpp | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Data Structures/Graph/Undirected Graph/UndirectedGraphMatrix.cpp diff --git a/Data Structures/Graph/Undirected Graph/UndirectedGraphMatrix.cpp b/Data Structures/Graph/Undirected Graph/UndirectedGraphMatrix.cpp new file mode 100644 index 0000000..4849aaf --- /dev/null +++ b/Data Structures/Graph/Undirected Graph/UndirectedGraphMatrix.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; +#define Max 10 +int graph[Max][Max]; +void addEdge(int u,int v){ + graph[u][v]=1; + graph[v][u]=1; +} + +void prints(){ + cout<<" "; + for(int j=1;j Date: Wed, 20 Oct 2021 17:35:11 +0530 Subject: [PATCH 3/3] Adding undirected graph using adjacency list --- .../UndirectedGraphAdjacenyList.cpp | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Data Structures/Graph/Undirected Graph/UndirectedGraphAdjacenyList.cpp diff --git a/Data Structures/Graph/Undirected Graph/UndirectedGraphAdjacenyList.cpp b/Data Structures/Graph/Undirected Graph/UndirectedGraphAdjacenyList.cpp new file mode 100644 index 0000000..09a302a --- /dev/null +++ b/Data Structures/Graph/Undirected Graph/UndirectedGraphAdjacenyList.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include +#define Max 10 +using namespace std; +list g[Max]; +void addEdge(int u,int v){ + g[u].push_back(v); + g[v].push_back(u); + +} + +void print(){ + list::iterator ptr; + for(int i=1;i"; + for(ptr=g[i].begin();ptr!=g[i].end();ptr++){ + cout<<*ptr<<" "; + } + cout<