Skip to content

Commit 050cd02

Browse files
committed
add: initial implementation of Rabin-Karp algorithm for string matching
1 parent d2f326f commit 050cd02

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/java/com/thealgorithms/strings/PatternSearchUsingRabinKarpAlgo.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.thealgorithms.strings;
2-
import java.util.*;
2+
import java.util.ArrayList;
3+
import java.util.List;
4+
import java.util.Scanner;
35

46
/*
7+
@author Lohit M Kudlannavar (https://github.com/Lohit-pro)
8+
59
https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm
610
The Rabin-Karp algorithm calculates a hash value for the pattern and a hash value for a sliding window
711
of text in the same length as the pattern. If the hash values match, it checks character by character
@@ -10,6 +14,9 @@
1014

1115
public class PatternSearchUsingRabinKarpAlgo {
1216

17+
private PatternSearchUsingRabinKarpAlgo() {
18+
}
19+
1320
// I'm using Rabin-Karp algorithm that uses hashing to find pattern strings in a text.
1421
public static List<String> search(String text, String pattern) {
1522
List<String> result = new ArrayList<>();
@@ -73,7 +80,7 @@ public static void main(String[] args) {
7380

7481
System.out.print("Enter the searching string: ");
7582
String pattern = in.next();
76-
// String pattern = "CDD"; testt
83+
// String pattern = "CDD"; test
7784

7885
List<String> result = search(text.toLowerCase(), pattern.toLowerCase());
7986

0 commit comments

Comments
 (0)