Unit5
Unit5
Unit5
Noida
Unit: 5
• In Data mining
• Image Processing
• Digital Signature.
• DNA Matching.
CO To analyze and apply different optimization techniques like Knowledge, Analysis And
4 dynamic programming, backtracking and Branch & Bound to Apply
solve the complex problems
CO To understand the advanced concepts like NP Completeness and Knowledge, Analysis and
5 Fast Fourier Transform, to analyze and apply String Matching, Apply
Approximation and Randomized Algorithms to solve the
complex problems
PO1
CO.K PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO12
1
ACSE0401.1 3 3 3 3 2 - - - 2 2 - 3
ACSE0401.2 3 3 3 3 2 2 - 1 1 1 - 3
ACSE0401.3 3 3 2 3 3 2 - 2 1 1 2 3
ACSE0401.4 3 3 3 3 2 2 - 2 2 1 3 3
ACSE0401.5 2 2 2 2 2 2 - 2 1 1 1 2
Average 2.8 2.8 2.6 2.8 2.2 1.6 - 1.8 1.4 1.2 1.2 2.8
B TECH
(SEM-V) THEORY EXAMINATION 20__-20__
COMPILER DESIGN
Time: 3 Hours Total
Marks: 100
Note: 1. Attempt all Sections. If require any missing data; then choose
suitably.
SECTION A
1.Q.No.
Attempt all questions in brief.
Question Marks 2 COx 10
1 = 20 2
2 2
. .
10 2
SECTION B
2. Attempt any three of the following: 3 x 10 = 30
1 10
2 10
ANKITA SHARMA 12/8/24
ACSE0401 Design and analysis of Algorithm Unit V 11
End Semester Question Paper Templates
1 10
2 10
5. Attempt any one part of the following: 1 x 10 = 10
Q.No. Question Marks CO
1 10
2 10
6. Attempt any one part of the following: 1 x 10 = 10
Q.No. Question Mark CO
s
1 10
2 10
• Prerequisite
• Basic concept of c programming language.
• Concept of stack, queue and link list.
• Recap
• Flow Chart
• Algorithm
• Algebraic Computation
• Fast Fourier Transform
• . String Matching
• Theory of NP-completeness
• Approximation algorithms
• Randomized algorithms.
Algebraic Structures
• Basic requirements
– precise representation of algebraic structures
• Can be represented by
– Representation of integers
– Representation of polynomials
– Representation of expressions
• Fourier analysis converts a signal from its original domain (often time or
space) to a representation in the frequency domain and vice versa.
• The difference in speed can be enormous, especially for long data sets
where N may be in the thousands or millions.
ANKITA SHARMA ACSE0401 Design and analysis of Algorithm
12/8/24 21
Unit V
Algebraic Computation(CO5)
DFT(a0,a1,…,an−1) =(y0,y1,…,yn−1)
=(A(wn,0),A(wn,1),…,A(wn,n−1)
=(A(w0n),A(w1n),…,A(wn−1n))
• The fast Fourier transform is a method that allows computing the DFT
in O(nlogn) time.
Inverse DFT
InverseDFT(y0,y1,…,yn−1) = (a0,a1,…,an−1)
Prerequisite
• Algorithms
• Finite automata
Recap
• Algebraic Computation
• The item of P and T are character drawn from some finite alphabet such as
{0, 1,2…9} or {A, B .....Z, a, b..... z}.
• Using these descriptions, we can say given any string T [1......n], the
substrings are
T [i.....j] = T [i] T [i +1] T [i+2]......T [j] for some 0≤i ≤ j≤n-1.
• Note: If i>j, then T [i.....j] is equal to the empty string or null, which
has length zero.
• The Rabin-Karp-Algorithm
• Finite Automata
Ø 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)
• 1. n ← length [T]
• 2. m ← length [P]
• 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)
• Example:
Suppose T = 1011101110 , P = 111 . Find all the Valid Shift
Solution:
•
• If the hash values are unequal, the algorithm will determine the hash
value for next M-character sequence.
• If the hash values are equal, the algorithm will analyze the pattern
and the M-character sequence.
• In this way, there is only one comparison per text subsequence, and
character matching is only required when the hash values match.
T = 31415926535.......
P = 26
Here T.Length =11 so Q = 11
And P mod Q = 26 mod 11 = 4
Now find the exact match of P mod Q...
Solution:
• It examines every character in the text exactly once and reports all
the valid shifts in O (n) time.
• The finite automaton starts in state q0 and reads the characters of its input
string one at a time.(So time complexity O(n))
• If the automaton is in state q and reads input character a, it moves from state
q to state δ (q, a).
• Whenever its current state q is a member of A, the machine M has accepted
the string read so far. An input that is not allowed is rejected.
1. The Prefix Function (Π): The Prefix Function, Π for a pattern encapsulates
knowledge about how the pattern matches against the shift of itself. This
information can be used to avoid a useless shift of the pattern 'p.' In other
words, this enables avoiding backtracking of the string 'S.’
2. The KMP Matcher: With string 'S,' pattern 'p' and prefix function 'Π' as
inputs, find the occurrence of 'p' in 'S' and returns the number of shifts of 'p'
after which occurrences are found.
In the above pseudo code for calculating the prefix function, the for loop from step 4 to
step 10 runs 'm' times. Step1 to Step3 take constant time. Hence the running time of
computing prefix function is O (m).
Solution:
Initially: m = length [p] = 7 Π [1] = 0 k = 0
Prerequisite
• Different Problems like graph colouring
• Travelling Salesman Problem
Recap
• String Matching Algorithm
• Algorithms for solving real world problems
P is subset of
12/8/24 NP
ANKITA SHARMA ACSE0401 Design and analysis of Algorithm Unit V 60
NP Completeness(CO5)
• NP-Complete Problems
Following are some NP-Complete problems, for which no polynomial
time algorithm is known.
• Determining whether a graph has a Hamiltonian cycle
• Determining whether a Boolean formula is satisfiable, etc.
• NP-Hard Problems
The following problems are NP-Hard
• The circuit-satisfiability problem
• Set Cover
• Vertex Cover
• Travelling Salesman Problem
Circuit Satisfiability
According to given decision-based NP problem, we can design the
CIRCUIT and verify a given mentioned output also within the P time.
The CIRCUIT is provided below:-
Example:
U = {1,2,3,4,5}, S = {S1,S2,S3}
S1 = {4,1,3}, Cost(S1) = 5
S2 = {2,5}, Cost(S2) = 10
S3 = {1,4,3,2}, Cost(S3) = 3
Output: Minimum cost of set cover is 13 and set cover is {S2, S3}
There are two possible set covers {S1, S2} with cost 15 and {S2, S3}
with cost 13
Example:
The set of edges of the given graph is −
{(1,6),(1,2),(1,4),(2,3),(2,4),(6,7),(4,7),(7,8),(3,8),(3,5),(8,5)}
• The salesman has to visit each one of the cities starting from
a certain one and returning to the same city.
Proof
• In TSP, we find a tour and check that the tour contains each vertex
once.
• Conversely, we assume that G' has a tour h' of cost at most 0. The
cost of edges in E' are 0 and 1 by definition. Hence, each edge
must have a cost of 0 as the cost of h' is 0. We therefore conclude
that h' contains only edges in E.
4. Explain Rabin Karp algorithm. For the text 2359023141526739921 and for
the pattern 31415 and working modulo q=13 how many valid match and
spurious hits does the Rabin matcher encounter. [CO5]
Q.4 Problems that cannot be solved by any algorithm are called _________.
a) tractable problems
b) intractable problems
c) undecidable problems
d) decidable problems
Q.5 Halting problem is an example for___________.
a) decidable problem
b) undecidable problem
c) complete problem
d) trackable problem.
Q.6 __________conditions have to be met if an NP- complete problem is
polynomially reducible?
a) 1
b) 2
c) 3
d) 4
ANKITA SHARMA ACSE0401 Design and analysis of Algorithm
12/8/24 Unit V 87
Glossary Question
12/8/24 ANKITA SHARMA ACSE0401 Design and analysis of Algorithm Unit V 100
Old Question Papers(2020-2021)
12/8/24 ANKITA SHARMA ACSE0401 Design and analysis of Algorithm Unit V 102
Old Question Papers(2020-2021)
12/8/24 ANKITA SHARMA ACSE0401 Design and analysis of Algorithm Unit V 103
Expected Questions for University Exam
12/8/24 ANKITA SHARMA ACSE0401 Design and analysis of Algorithm Unit V 104
Recap Of Unit
12/8/24 ANKITA SHARMA ACSE0401 Design and analysis of Algorithm Unit V 105
Unit 5
Thank You
12/8/24 ANKITA SHARMA ACSE0401 Design and analysis of Algorithm Unit V 106