Professional Documents
Culture Documents
Weightage in
Bloom Level: K3 Marks: 10(
Duration in
Unit:5 minutes: 10
Topic Name: String Matching Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:1 Explain different String Matching Algorithm
Solution: 3 String matching algorithms is to find one, several, or all
(With step wise occurrences of a defined string (pattern) in a large string
marking) (text or sequences) such that each matching is perfect. All
alphabets of patterns must be matched to corresponding
matched subsequence. These are further classified into four
categories:
1. Algorithms based on character comparison:
Naive Algorithm: It slides the pattern over text
one by one and check for a match. If a match is
found, then slides by 1 again to check for
subsequent matches.
KMP (Knuth Morris Pratt) Algorithm: The idea
is whenever a mismatch is detected, we already
know some of the characters in the text of the
next window. So, we take advantage of this
information to avoid matching the characters
that we know will anyway match.
Boyer Moore Algorithm: This algorithm uses
best heurestics of Naive and KMP algorithm
and starts matching from the last character of
the pattern.
Using the Trie data structure: It is used as an
efficient information retrieval data structure. It
stores the keys in form of a balanced BST.
2. Deterministic Finite Automaton (DFA) method:
Automaton Matcher Algorithm: It starts from
the first state of the automata and the first
character of the text. At every step, it considers
next character of text, and look for the next
state in the built finite automata and move to a
new state.
3. Algorithms based on Bit (parallelism method):
Aho-Corasick Algorithm: It finds all words in
O(n + m + z) time where n is the length of text
and m be the total number characters in all
words and z is total number of occurrences of
words in text. This algorithm forms the basis of
the original Unix command fgrep.
4. Hashing-string matching algorithms:
Rabin Karp Algorithm: It matches the hash
value of the pattern with the hash value of
current substring of text, and if the hash values
match then only it starts matching individual
characters.
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K3 Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Approximation Question Type:
Topic Name: Algorithm Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:2 What do you mean by approximation algorithm?Explain,
Approximate String Matching Algorithms (also known as
Fuzzy String Searching) searches for substrings of the input
string. More specifically, the approximate string matching
approach is stated as follows: Suppose that we are given two
strings, text T[1…n] and pattern P[1…m]. The task is to find
all the occurrences of patterns in the text whose edit distance
to the pattern is at most k. Some well known edit distances
are – Levenshtein edit distance and Hamming edit distance.
These techniques are used when the quality of the text is low,
Solution:
there are spelling errors in the pattern or text, finding DNA
(With step wise
subsequences after mutation, heterogeneous databases, etc.
marking)
Some approximate string matching algorithms are:
Naive Approach: It slides the pattern over text one by
one and check for approximate matches. If they are
found, then slides by 1 again to check for subsequent
approximate matches.
Sellers Algorithm (Dynamic Programming)
Shift or Algorithm (Bitmap Algorithm)
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Suppose that all characters in the pattern P are different. Show
Question:5 how to accelerate NAIVE-STRING-MATCHER to run in time O.n/
on an n-character text T .
We know that one occurrence of P in T cannot overlap with
Solution: another, so we don’t need to double-check the way the naive
(With step wise algorithm does. If we find an occurrence of Pk in the text followed
marking) by a nonmatch, we can increment s by k instead of 1. It can be
modified in the following way:
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:6
For any particular value of s, the probability that the ith character
Solution: will need to be looked at when doing the string comparison is the
(With step wise probability that the first i − 1 characters matched, which is 1 di−1 .
marking) So, by linearity of expectation, summing up over all s and i, we
have that the expected number of steps is, by equation (A.5),
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K3 Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:7
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
How would you extend the Rabin-Karp method to the problem
of searching a text string for an occurrence of any one of a given
Question:9 set of k patterns? Start by assuming that all k patterns have the
same length. Then generalize your solution to allow the
patterns to have different lengths.
We first tackle the case where each of the k patterns has the same
length m. We first compute the number associated to each pattern in
O(m) time, which contributes O(km) to the runtime. In line 10 we
make k checks, one for each pattern, which contributes O(n − m +
Solution: 1)km time. Thus, the total runtime is O(km(n − m + 1). For patterns
(With step wise of different lengths l1, l2, . . . , lk, keep an array A such that A[i]
marking) holds the number associated to the first li digits of T, mod q. We’ll
have to update each of these each time the outer for-loop is
executed, but it will allow us to immediately compare any of the
pattern numbers to the appropriate text number, as done in line 10.
add in the entries that are in the right column, also appropriately
scaled by what row they are in. Similarly for shifting the window
up or down. Again, all of this arithmetic is done mod some large
prime.
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:11
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Construct the string-matching automaton for the pattern P D
Question:12 aabab and illustrate its operation on the text string T D
aaababaabaababaab.
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Draw a state-transition diagram for a string-matching
Question:13 automaton for the pattern ababbabbababbababbabb over the
alphabet = {a, b}.
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
We call a pattern P nonoverlapable if Pk ⊐ Pq implies k = 0 or k
Question:14 = q. Describe the state-transition diagram of the string-
matching automaton for a nonoverlappable pattern.
The state transition function looks like a straight line, with all other
edges going back to either the initial vertex (if it is not the first
letter of the patter) or the second vertex (if it is the first letter of the
Solution:
pattern). If it were to go back to any later state, that would mean
(With step wise
that some suffix of what we had constructed so far(which was a
marking)
prefix of P) was a prefix of the copy of P that we are next trying to
find.
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Given two patterns P and P’ , describe how to construct a finite
Question:15 automaton that determines all occurrences of either pattern.
Try to minimize the number of states in your automaton.
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:16
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Bloom Level: K Weightage in 10(2+5+3)
Marks:
Unit:5 Duration in 10
minutes:
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Compute the prefix function for the pattern
Question:17 ababbabbabbababbabb.
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Bloom Level: K Weightage in 10(2+5+3)
Marks:
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:18
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Explain how to determine the occurrences of pattern P in the text T
by examining the function for the string P T (the string of length
Question:19
m+n that is the concatenation of P and T ).
Solution:
(With step wise
marking)
suffix of any other prefix.
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:20 Use an aggregate analysis to show that the running time of KMP-
MATCHER is (n).
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Use a potential function to show that the running time of KMP-
Question:21
MATCHER is (n).
Basically, each time that we have to execute line 7, we have that we
are decreasing q by at least 1. Since the only place that we ever
increase the value of q is on line 9, and then we are only increasing
it by 1, each of these runs of line 5 are paid for by the times we ran
9. Using this as our motivation, we let the potential function be
proportional to the value of q. This means that when we execute
line 9, we pay a constant amount to raise up the potential function.
Solution:
And when we run line 7, we decrease the potential function which
(With step wise
reduces the ammortized cost of an iteration of the while loop on
marking)
line 6 to a zero amortized cost. The only other time that we change
the value of q is on line 12, which only gets run once per execution
of the outer for loop anyways and the amortization is in our favor
there. Since the ammortized cost under this potential function of
each iteration of the outermost for loop is constant, and that loop
runs n times, the total cost of the algorithm is Θ(n).
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:22
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Give a linear-time algorithm to determine whether a text T is a
cyclic rotation of another string T 0 . For example, arc and car are
Question:23
cyclic rotations of each other.
Question:24
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:25
First, compute the prefix array for the given pattern in linear time .
Then, Suppose that π[i] = i−k. If k|i, we know that k is the length of
the primitive root, so, the word has a repetition factor of i k . We
also know that there is no smaller repetition factor in this case
because otherwise we could include one more power of that root.
Now, suppose that we have k not dividing i. We will show that we
Solution:
can only have the trivial repetition factor of 1. Suppose we had
(With step wise
some repetition y r = Pi . Then, we know that π[i] ≥ y r−1 .
marking)
however, if we have it strictly greater than this, this means that we
can write the y’s themselves as powers because we have them
aligning with themselves. Since the only difficult step of this was
finding the prefix function, which takes linear time, the runtime of
this procedure is linear.
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:26
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:27
This algorithm correctly finds the occurrences of the pattern P for
reasons similar to the Knuth Morris Pratt algorithm. That is, we
know that we will only increase q ρ∗ (P) many times before we
Solution:
have to bite the bullet and increase s, and s can only be increased at
(With step wise
most n − m many times. It will definitely find every possible
marking)
occurrence of the pattern because it searches for every time that the
primitive root of P occurs, and it must occur for P to occur.
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:28
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:29
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:30
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Bloom Level: K Weightage in 10(2+5+3)
Marks:
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Unit:5 Duration in 10
minutes:
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:33
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:34
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Unit:5 Duration in 10
minutes:
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:36
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:37
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:38
Solution:
(With step wise
marking)
Question:39
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:40
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:41
Show that the hamiltonian-path problem from Exercise 34.2-6 can
be solved in polynomial time on directed acyclic graphs. Give an
efficient algorithm for the problem.
Reference
Book/Link: Coreman
Format of Subjective Question Bank
K Weightage in 10(2+5+3)
Bloom Level: Marks:
Duration in 10
Unit:5 minutes:
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:42
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:44
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective
Lecture No. as per Subjective/
GATE/PSU/Indust
LDS: ry
Question:45
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Verify that the circuit in Figure 34.8(b) is unsatisfiable.
Question:46
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Question:47
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Question:48
Solution:
(With step wise
marking)
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10(2+5+3)
Duration in
Unit:5 minutes: 10
Topic Name: Question Type:
Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
Reference
Book/Link: Coreman
Reference
Book/Link: Coreman and Geek For Geeks
Reference
Book/Link: Coreman and Geek For Geeks
Reference
Book/Link: Coreman and Geek For Geeks