Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions BMA.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package Algorithms;
public class BMA
{
String zx=" ";
/*public static void main(String[] args)
{
//(BoyerMoore("Is the pattern a substring?", "substr"));
}*/

public void BoyerMoore(String T, String P)
public boolean BoyerMoore(String T, String P)
{
int flag=0,pos=0;
int i = P.length() -1;
Expand All @@ -20,6 +21,7 @@ public void BoyerMoore(String T, String P)
pos=i;
flag=1;// pattern found
System.out.println("Pattern found at position: "+ pos);
zx=zx+" "+pos;
break;

}
Expand All @@ -37,10 +39,14 @@ public void BoyerMoore(String T, String P)
} while(i <= T.length()-1);

if(flag==1)
{
System.out.println("Pattern found at position: "+ pos);
else
return true;
}
else {
System.out.println("Pattern not found");

return false;
}
}
// Returns index of last occurrence of character in pattern.

Expand All @@ -67,4 +73,4 @@ else if (b < a)
else
return a;
}
}
}
4 changes: 2 additions & 2 deletions Execute.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public static void main(String args[])

Scanner sc=new Scanner(System.in);
System.out.println("Enter the string: ");
String givenstr=sc.next();
System.out.println("Enter the Pattern to be matched: ");
String givenstr=sc.nextLine();
System.out.println("Enter the Pattern to be matchAed: ");
String pattern = sc.next();

while(true) {
Expand Down
18 changes: 12 additions & 6 deletions KMP.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package Algorithms;
public class KMP
{

String zx=" ";
/* public static void main(String[] args) {
final String givenstr = "AAAAABAAABA"; //This is the full string
final String pattern= "AAAA"; //This is the substring that we want to find
KMPmatcher(haystack, needle);
}*/

public static void KMPmatcher(final String givenstr, final String pattern) {
final int m = givenstr.length();
final int n = pattern.length();
boolean KMPmatcher(String givenstr, String pattern) {
int m = givenstr.length();
int n = pattern.length();
int flag=0;
final int[] pi = computePrefixFunction(pattern);
int[] pi = computePrefixFunction(pattern);
int q = 0;
for (int i = 0; i < m; i++) {
while (q > 0 && givenstr.charAt(i) != pattern.charAt(q)) {
Expand All @@ -27,10 +27,16 @@ public static void KMPmatcher(final String givenstr, final String pattern) {
flag=1;
System.out.println("Pattern found at " + (i + 1 - n));
q = pi[q - 1];
zx=zx+" "+(i + 1 - n);
}
}
if(flag==0)
if(flag==0) {
System.out.println("Pattern not found");
return false;
}
else {
return true;
}
}

// return the prefix function
Expand Down
21 changes: 13 additions & 8 deletions Naive.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import java.util.*;
public class Naive
{
public static void Naivesearch(String pattern, String givenstr)
int flag=0;
public boolean Naivesearch(String pattern, String givenstr)
{
int m = pattern.length();
int n = givenstr.length();
int flag=0,i=0;
int i=0;
for (i = 0; i <= n - m; i++)
{
int j;
Expand All @@ -21,20 +22,24 @@ public static void Naivesearch(String pattern, String givenstr)
}
}
if(flag==1)
System.out.println("Pattern found");
else
{
System.out.println("Pattern present in the string");
return true;
}
else {
System.out.println("Pattern not found");
}

public static void main(String[] args)
return false;
}
}
/*public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string: ");
String givenstr=sc.next();
System.out.println("Enter the Pattern to be matched: ");
String pattern = sc.next();
Naivesearch(pattern,givenstr);
}
} */
}


8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Advanced Algorithm Project
## Search Algorithms Visualizer in Java Swing
Algorithms like
- Naive Bayes
- Knuth,Morris & Pratt
- Boyer Moore
- Rabin Karp
Are demonstrated
18 changes: 14 additions & 4 deletions Rabin_karp.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package Algorithms;
public class Rabin_karp
{
int flag=0;
String zx=" ";
//number of characters in the input alphabet
public final static int d = 256;

void RKsearch(String pat, String txt, int q)
boolean RKsearch(String pat, String txt, int q)
{
int M = pat.length();
int N = txt.length();
int i, j,flag=0;
int i, j;
int p = 0; // hash value for pattern
int t = 0; // hash value for txt
int h = 1;
Expand Down Expand Up @@ -42,7 +44,10 @@ void RKsearch(String pat, String txt, int q)
// if pattern exists in text
if (j == M) {
flag=1;
System.out.println("Pattern found at index " + i); }
System.out.println("Pattern found at index " + i);
zx=zx+" "+i;
System.out.println(zx);
}
}

if ( i < N-M )
Expand All @@ -54,8 +59,13 @@ void RKsearch(String pat, String txt, int q)
t = (t + q);
}
}
if(flag==0)
if(flag==0) {
System.out.println("Pattern not found");
return false;
}
else {
return true;
}

}

Expand Down
64 changes: 0 additions & 64 deletions bleh.java

This file was deleted.

Loading