Uploaded by Muhammad Owais Idrees

Assignment-4-Algo-Spr-2022

advertisement
CS-2009 Design and Analysis of Algorithms-Spring 2022
Assignment 4
Due Date and Time: 21 April, 2022 (11:30 hrs)
Weight: 2%
Instructions:
1. Late assignment will not be accepted
2. Only handwritten attempt will be graded, i.e., printed attempts will not be graded
3. Only the attempts submitted to Mr. Fahad or Mr. Amir in the Academic office (till
the due date & time) will be considered, i.e., the submissions that will be slided
beneath instructors’ office doors or submitted elsewhere will not be graded.
4. There will be no credit if the given requirements are changed
5. Your solution will be evaluated in comparison with the best solution
6. Please mention the question number and its part (if any) before writing down its
solution. Use the same conventions used in the assignment’s statement document.
7. Plagiarism may result in zero marks in the whole assignments category (all
assignments) regardless of the percentage plagiarized.
Q1. A cyclic rotation of a string is obtained by chopping off a prefix and gluing it at the
end of the string. For example, ALGORITHM is a cyclic shift of RITHMALGO. Describe
(in pseudocode form) and analyze (running time in Big-O notation) an algorithm that
determines whether one string P[1...m] is a cyclic rotation of another string T[1...n].
[0.40%]
Q2. Show the comparisons that the naive string matcher makes for the pattern
P = “10001” in the text T = “10000100010100010000”.
[0.20%]
Q3. Show the complete working of Rabin-Karp String Matching algorithm for the
following pattern P and Text T. [0.40%]
T= “12049119419470015329845”
P= “1947”
1. Working modulo q = 5
2. Working modulo q =17
Also show that how many spurious hits the Rabin-Karp matcher encounters for both
values of q?
Q4. The suffix function σ(x) specifies the length of the longest prefix of pattern P that is
also a suffix of x.
Show the result of the following suffix function σ(x), for the pattern P = “ffaasstt”
[0.20%]
i.
σ(off)=2
ii.
σ(cffa)=3
iii.
σ(fast)=
iv.
σ(staaff)=
v.
σ(pastt)=
vi.
σ(ttssaaff)=
vii.
σ(ifffaa)=
viii.
σ(fffaasstt)=
ix.
σ(fffaasst)=
x.
σ(fffaasstt)=
xi.
σ(pakfffaasstt)=
xii.
σ(quettaafffaass)=
Q5. Draw the state transition table and state transition diagram for the pattern
P=ccaabbaabbaabbcca over the alphabet ∑ ={a,b,c} using the following function:
[0.40%]
NOTE: There will be zero marks for only showing the transition table and the state transition
diagram without showing the dry run of every step performed for making the transition table
Q6. [0.40%]
a.
Compute the prefix function ∏ for the pattern P = “aaggac”
b.
Find the above mentioned pattern in the text
T = “ctgcggcaaaggaaaaaaggaaaaaaggaataaaac”, using KMP String
matching algorithm. Show all the Steps.
Download