KMP Algorithm:
The Knuth-Morris-Pratt algorithm is used to find a given text from a specific word.
This algorithm uses the degenerating property which primarily works based on sub-strings.
The basic idea of this algorithm is to not match a character which is already known to match for sure.
Example:
Output: Enter the pattern to be found:
Input: cktober
Output : Enter the string in which the pattern is to be found:
Input: hacktoberfest
Output/Answer: Pattern found at index: 2
Rabin Karp Algorithm
The Rabin karp Algorithm is used to search a text from a given word using hash function.
This algorithm doesnt search slide through every character but filters the unlike characters and then does the comparing.
Example:
Enter the pattern to be found:
program
Enter the string in which the pattern is to be found:
competitveprogramming
Pattern found at index: 10