You are on page 1of 35

Format of Subjective Question Bank

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)

Reference Coreman and Geek For Geeks


Book/Link:
Format of Subjective Question Bank
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:3 Explain Different Applications of String Matching Algorithm.
Applications of String Matching Algorithms:
 Plagiarism Detection: The documents to be
compared are decomposed into string tokens and
compared using string matching algorithms. Thus,
these algorithms are used to detect similarities
between them and declare if the work is plagiarized or
original.

Solution:
(With step wise
marking)

 Bioinformatics and DNA Sequencing:


Bioinformatics involves applying information
technology and computer science to problems
involving genetic sequences to find DNA patterns.
String matching algorithms and DNA analysis are both
collectively used for finding the occurrence of the
pattern set.
 Digital Forensics: String matching algorithms are
used to locate specific text strings of interest in the
digital forensic text, which are useful for the
investigation.
 Spelling Checker: Trie is built based on a predefined
set of patterns. Then, this trie is used for string
matching. The text is taken as input, and if any such
pattern occurs, it is shown by reaching the acceptance
state.

 Spam filters: Spam filters use string matching to


discard the spam. For example, to categorize an email
as spam or not, suspected spam keywords are
searched in the content of the email by string
matching algorithms. Hence, the content is classified
as spam or not.
 Search engines or content search in large
databases: To categorize and organize data
efficiently, string matching algorithms are used.
Categorization is done based on the search keywords.
Thus, string matching algorithms make it easier for
one to find the information they are searching for.

 Intrusion Detection System: The data packets


containing intrusion-related keywords are found by
applying string matching algorithms. All the malicious
code is stored in the database, and every incoming
data is compared with stored data. If a match is found,
then the alarm is generated. It is based on exact string
matching algorithms where each intruded packet
must be detected.
Reference
Book/Link: Coreman and Geek For Geeks
Format of Subjective Question Bank
Weightage in
Bloom Level: K Marks: 10
Duration in
Unit:5 minutes: 10
String Matching Question Type:
Topic Name: Algorithm Subjective/
Subjective
Lecture No. as per GATE/PSU/Indust
LDS: ry
What do you mean by Naive StringMatching ?Write Steps of
Question:4
Algorithm
The naïve approach tests all the possible placement of Pattern P
[1.......m] relative to text T [1......n]. We try shift s = 0, 1.......n-m,
successively and for each shift s. Compare T [s+1.......s+m] to P
[1......m].
The naïve algorithm finds all valid shifts using a loop that
checks the condition P [1.......m] = T [s+1.......s+m] for each of the
n - m +1 possible value of s.
NAIVE-STRING-MATCHER (T, P)
Solution:
1. n ← length [T]
(With step wise
2. m ← length [P]
marking)
3. for s ← 0 to n -m
4. do if P [1.....m] = T [s + 1....s + m]
5. then print "Pattern occurs with shift" s

Analysis: This for loop from 3 to 5 executes for n-m + 1(we


need at least m characters at the end) times and in iteration we
are doing m comparisons. So the total complexity is O (n-m+1).

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

Note that the gap character may occur an arbitrary number of


times in the pattern but not at all in the text. Give a polynomial-
time algorithm to determine whether such a pattern P occurs in
a given text T , and analyze the running time of your algorithm.
Solution: We can decompose a pattern with g−1 gap characters into the form
(With step wise a1 a2 · · · ag. Since we only care whether or not the pattern
appears somewhere, it will suffice to look for the first occurrence of
a1, followed by the first occurrence of a2 which comes anywhere
marking) after a1, and so on. If the pattern P has length m and the text has
length n then the runtime of the naive strategy is O(nm).

Reference Coreman and Geek For Geeks


Book/Link:
Format of Subjective Question Bank
K3 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
Working modulo q D 11, how many spurious hits does the
Question:8 Rabin-Karp matcher encounter in the text T D
3141592653589793 when looking for the pattern P D 26?
We can decompose a pattern with g−1 gap characters into the form
a1 a2 · · · ag. Since we only care whether or not the pattern
appears somewhere, it will suffice to look for the first occurrence of
a1, followed by the first occurrence of a2 which comes anywhere
after a1, and so on. If the pattern P has length m and the text has
length n then the runtime of the naive strategy is O(nm).

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.

Reference Coreman and Geek For Geeks


Book/Link:
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
Show how to extend the Rabin-Karp method to handle the
problem of looking for a given m m pattern in an n n
Question:10
array of characters. (The pattern may be shifted vertically and
horizontally, but it may not be rotated.)
Solution:
(With step wise
marking)

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

and Bob similarly evaluates B.x/. Prove that if A ¤ B, there is at


most one chance in 1000 that A.x/ D B.x/, whereas if the two
files are the same, A.x/ is necessarily the same as B.x/.

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

show how to build a finite automaton that can find an


occurrence of P in a text T in O(n) matching time, where n =|T|.
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:
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.

If the lengths to T and T 0 are different, they are obviously not


cyclic rotations of each other, so suppose that |T| = T 0 . Let our
text be T T and our pattern be T 0 . If and only if T 0 occurs in T T,
then the two given strings are cyclic rotations of each other. This
can be done in linear time by the Knuth Morris Pratt algorithm. To
see that being cyclic rotations means that T 0 occurs in T T,
suppose that T 0 is obtained from T by cyclically shifting the right
Solution:
character to the left s times. This means that the |T| − s prefix of T
(With step wise
is a suffix of T 0 , and the s suffix of T is a prefix of T 0 . This
marking)
means that T 0 occurs in T T with a shift of |T| − s. Now, suppose
that T 0 occurs in T T with a shift of s. This means that the s suffix
of T is a prefix of T 0 , it also means that the |T| − s characters left
over in T 0 are a prefix of T. So, they are cyclic rotations of each
other.

Reference Coreman and Geek For Geeks


Book/Link:
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: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

Is the dynamic-programming algorithm for the 0-1 knapsack


Question:31
problem a polynomial-time algorithm? Explain your answer

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

Show that if an algorithm makes at most a constant number of calls


to polynomialtime subroutines and performs an additional amount
Question:32 of work that also takes polynomial time, then it runs in polynomial
time. Also show that a polynomial number of calls to polynomial-
time subroutines may result in an exponential-time algorithm.

We show the first half of this exercise by induction on the number


of times that we call the polynomial time subroutine. If we only call
it zero times, all we are doing is the polynomial amount of extra
work, and therefore we have that the whole procedure only takes
polynomial time. Now, suppose we want to show that if we only
make n + 1 calls to the polynomial time subroutine. Consider the
execution of the program up until just before the last call. At this
point, by the inductive hypothesis, we have only taken a polynomial
amount of time. This means that all of the data that we have
constructed so far fits in a polynomial amount of space. This means
that whatever argument we pass into the last polynomial time
subroutine will have size bounded by some polynomial. The time
that the last call takes is then the composition of two polynomials,
Solution: and is therefore a polynomial itself. So, since the time before the
(With step wise last call was polynomial and the time of the last call was
marking) polynomial, the total time taken is polynomial in the input. This
proves the claim of the first half of the input. To see that it could
take exponential time if we were to allow polynomially many calls
to the subroutine, it suffices to provide a single example. In
particular, let our polynomial time subroutine be the function that
squares its input. Then our algorithm will take an integer x as input
and then square it lg(x) many times. Since the size of the input is
lg(x), this is only linearly many calls to the subroutine. However,
the value of the end result will be x 2 lg(x) = x x = 2x lg(x) = 2lg(x)2lg(x) ∈
ω(2 2 lg(x) ). So, the output of the function will require exponentially
many bits to represent, and so the whole program could not of taken
polynomial time.

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

Prove that if G is an undirected bipartite graph with an odd number


Question:35
of vertices, then G is nonhamiltonian.

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)

Reference Coreman and Geek For Geeks


Book/Link:
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: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.

For a directed acyclic graph, we can compute the topological sort of


the graph by the method of section 22.4. Then, looking at this
sorting of the vertices, we say that there is a Hamiltonian path if as
we read off the vertices, each is adjacent to the next, and they are
not if there is any pair of vertices so that one is not adjacent to the
next. If we are in the case that each is adjacent to the next, then the
topological sort itself gives us the Hamiltonian path. However, if
there is any pair of vertices so that one is not adjacent to the next,
this means that that pair of vertices do not have any paths going
from one to the other. This would clearly imply that there was no
Solution: Hamiltonian path, because the Hamiltonian path would be going
(With step wise from one of them to the other. To see the claim that a pair of
marking) vertices u and v that are adjacent in a topological sort but are not
adjacent have no paths going from one to the other, suppose to a
contradiction there were such a path from u to v. If there were any
vertices along this path they would have to be after u since they are
descendants of u and they would have to be before v because they
are ancestors of v. This would contradict the fact that we said u and
v were adjacent in a topological sort. Then the path would have to
be a single edge from u to v, but we said that they weren’t adjacent,
and so, we have that there is no such path.

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 Coreman and Geek For Geeks


Book/Link:
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:43
A language is in coNP if there is a procedure that can verify that an
input is not in the language in polynomial time given some
certificate. Suppose that for that language we a procedure that could
compute whether an input was in the language in polynomial time
Solution: receiving no certificate. This is exactly what the case is if we have
(With step wise that the language is in P. Then, we can pick our procedure to verify
marking) that an element is not in the set to be running the polynomial time
procedure and just looking at the result of that, disregarding the
certificate that is given. This then shows that any language that is in
P is in coNP, giving us the inclusion that we wanted.

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

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: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

Show that we could have used a satisfying assignment as a


Question:49 certificate in an alternative proof of Lemma 34.5. Which certificate
makes for an easier proof?

Solution: We could have instead used as a certificate a satisfying assignment


(With step wise to the input variables in the proof of Lemma 34.5. We construct the
marking) two-input, polynomial time algorithm A to verify CIRCUIT-SAT
as follows. The first input is a standard encoding of a boolean
combinatiorial circuit C, and the second is a satisfying assignment
of the input variables. We need to compute the output of each logic
gate until the final one, and then check whether or not the output of
the final gate is 1. This is more complicated than the approach
taken in the text, because we can only evaluate the output of a logic
gate once we have successfully determined all input values, so the
order in which we examine the gates matters. However, this can
still be computed in polynomial time by essentially performing a
breath-first search on the circuit. Each time we reach a gate via a
wire we check whether or not all of its inputs have been computed.
If yes, evaluate that gate. Otherwise, continue the search to find
other gates, all of whose inputs have been computed.

Reference
Book/Link: Coreman

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
The proof of Lemma 34.6 assumes that the working storage for
algorithm A occupies a contiguous region of polynomial size.
Question:50 Where in the proof do we exploit this assumption? Argue that this
assumption does not involve any loss of generality.

We do not have any loss of generality by this assumption. This is


because since we bounded the amount of time that the program has
to run to be polynomial, there is no way that the program can access
Solution:
more than an polynomial amount of space. That is, there is no way
(With step wise
of moving the head of the turning machine further than
marking)
polynomially far in only polynomial time because it can move only
a single cell at a time.

Reference
Book/Link: Coreman and Geek For Geeks
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:60
Solution:
(With step wise
marking)

Reference
Book/Link: Coreman and Geek For Geeks

Contributors: CSE Department

You might also like