You are on page 1of 11

ALGO

Assignment 03

, 2020
Question 01:

Brute Force:

Output:

TEXT FILE:

Form Execution:
Case A:
CASE B:
CASE C:
CASE D:
No output message because string is not matched since case is checked and there
is no “ Is “ word in the file.
Output shown because string is matched since case is checked and
there is a “ This “ word in the file.
KMP:

Output:
Question 02:

ADVANTAGES OF BRUTE FORCE OVER KMP


NO PREPROCESSING:
The brute force algorithm is very simple technique and does not require preprocessing.
This algorithm is useful in cases where the source string and the desired pattern are
small. Other efficient algorithms require time and space to preprocess the desired
patterns, such as precomputing a Π table in KMP and hash function in the Robin-KARP
algorithm. Therefore, the total running time is equal to its matching time in this
algorithm.
SPACE EFFICIENT:
Brute force algorithm does not occupy extra space to perform the operation like KMP do
in prefix function(Π) which uses Ω(n) memory on a pattern string of length n.
EVALUATING ALGORITHMS:
Brute force algorithm is a tool for evaluating good algorithms.

ORDERLESS:
In brute force, Comparison can be done in any order.
OTHER PROS OF BRUTE FORCE:
o Wide applicability.
o Simplicity.
o It produces reasonable algorithms for some important problems such as
a) searching
b) string matching
c) matrix multiplication
o It produces standard algorithms for simple computational tasks such as
a) sum/product of numbers
b) finding max/min in a list
o Brute Force Algorithms refers to a style that does not include any shortcuts to
improve performance, but instead relies on thorough computing power to try all
possibilities until the solution to a problem is found. Because “Sometimes doing
better is not worth bother.”

ADVANTAGES OF RABIN-KARP OVER KMP


SPACE UTILIZATION FAVOURS RABIN-KARP:
Rabin-Karp uses O(1) in form of hash value, which is great when the desired pattern
string is too large. For example, if you're looking for all occurrences of a string of length
104  in a larger string of length 106, not having to allocate a table of 104 words for a prefix
function(Π) is a major win over KMP. In KMP, prefix function(Π) use Ω(n) memory on a
pattern string of length n, so Rabin- Karp algorithm will be efficient in this scenario.

PLAGIARISM DETECTION:
Robin-Karp algorithm is good when searching for large text that can find many patterns,
such as plagiarism detection. Meanwhile, KMP is good for searching within small
alphabets like in Bioinformatics or searching in binary strings but if the alphabet goes
up, it is less efficient.

MULTIPLE PATTERN MATCH:


It is amazing to say that the Robin-Karp algorithm is good for comparing multiple
patterns. In fact, its very nature supports such functionality, which is its advantage
compared to other string search algorithms.

FINGERPRINT SEARCH:
Rabin-Karp substring search is known as a fingerprint search because it uses a small
amount of information to represent a (potentially very large) pattern. Then it looks for
this fingerprint (the hash value) in the text. The algorithm is efficient because the
fingerprints can be efficiently computed and compared.

2D PATTERN:
Robin-Karp algorithm is more efficient in detection of 2D patterns than rest of the
algorithms.

You might also like