Design and Analysis Unit5
Design and Analysis Unit5
Noida
Unit: 5
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 2
Evaluation Scheme
12/24/2024 3
Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V
Syllabus
• In Data mining
• Image Processing
• Digital Signature.
• DNA Matching.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 5
Course Objective
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
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 7
Program Outcome
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 8
CO-PO and PSO Mapping
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
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 9
Program Educational Objectives(PEOs)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 10
Result Analysis
2022-23
Overall Result: 97%
Ms Priya(Section A): 98.4
Mr. Manish Chaudhry(Section B): 98.46
Ms. Priya(Section C): 94.28
2021-22
Overall Result: 94%
Mr. Nagesh Sharma (Section A&B): 95.59
Mr. Dileep Kushwaha (Section C): 94.12
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 11
End Semester Question Paper Template
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 xCO10 =
20
1 2
2 2
. .
10 2
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 12
End Semester Question Paper Templates
SECTION B
2. Attempt any three of the following: 3 x 10 = 30
1 10
2 10
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 13
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
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 14
Prerequisite and Recap
• Prerequisite
• Basic concept of c programming language.
• Concept of stack, queue and link list.
• Recap
• Flow Chart
• Algorithm
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 15
Unit Content
• Algebraic Computation
• Fast Fourier Transform
• . String Matching
• Theory of NP-completeness
• Approximation algorithms
• Randomized algorithms.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 16
Unit Objective
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 17
Topic Objective
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 18
Algebraic Computation(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 19
Algebraic Computation(CO5)
Algebraic Structures
• Basic requirements
– precise representation of algebraic structures
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 20
Algebraic Computation(CO5)
• Can be represented by
– Representation of integers
– Representation of polynomials
– Representation of expressions
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 21
Algebraic Computation(CO5)
• Fourier analysis converts a signal from its original domain (often time or space)
to a representation in the frequency domain and vice versa.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 22
, Algebraic Computation(CO5)
• The difference in speed can be enormous, especially for long data sets
where N may be in the thousands or millions.
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)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 27
Prerequisite and Recap
Prerequisite
• Algorithms
• Finite automata
Recap
• Algebraic Computation
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 28
String Matching (CO5)
• The item of P and T are character drawn from some finite alphabet such as
{0, 1} or {A, B .....Z, a, b..... z}.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 29
String Matching (CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 30
String Matching(CO5)
• 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.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 31
String Matching(CO5)
• The Rabin-Karp-Algorithm
• Finite Automata
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 32
String Matching(CO5)
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.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 33
String Matching(CO5)
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)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 34
String Matching(CO5)
• Example:
Suppose T = 1011101110 , P = 111 . Find all the Valid Shift
Solution:
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 35
String Matching(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 36
String Matching Algorithm (CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 37
String Matching(CO5)
• 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.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 38
String Matching(CO5)
1. nlength[T]
2. mlength[P]
3. hdm-1 mod q
4. p0
5. t0 0
6. For i1 to m (preprocessing)
7. do p(dp +P[i])modq
8. t0 (d t0 +T[i])modq
9. For s0 to n-m (matching)
10. do if p = ts
11. then if P[1…..m] = T[s +1,……..s+m]
12. then “Pattern occurs with shift” s
13.If s< n-m
14. then ts+1 (d(ts – T[s+1]h) + T[s+m+1]) mod q
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 39
String Matching(CO5)
Example: For string matching, working module q = 11, how many spurious
hits does the Rabin-Karp matcher encounters in Text T = 31415926535.......
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...
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 40
String Matching(CO5)
Solution:
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 41
String Matching(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 42
String Matching(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 43
String Matching(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 44
String Matching(CO5)
• It examines every character in the text exactly once and reports all
the valid shifts in O (n) time.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 45
String Matching(CO5)
• The finite automaton starts in state q0 and reads the characters of its input
string one at a time.
• 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.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 46
String Matching(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 47
String Matching(CO5)
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.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 48
String Matching(CO5)
The Prefix Function (Π)
Following pseudo code compute the prefix function, Π:
Compute-Prefix-function(P)
1. nlength[P]
2. Π[1]0
3. K0
4. for q2 to m
5. do while k > 0 and P[k+1] ≠ P[q]
6. do k Π[k]
7. if P[k+1] = P[q]
8. then k k+1
9. Π[q]k
10. Return Π
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).
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 49
String Matching(CO5)
Solution:
Initially: m = length [p] = 7 Π [1] = 0 k
=0
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 50
String Matching(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 51
String Matching(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 52
String Matching(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 53
String Matching(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 54
String Matching(CO5)
• On the other hand, it might be that a bad character is present in the pattern,
in this case, align the nature of the pattern with a bad character in the text.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 55
String Matching(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 56
NP Completeness(CO5)
Objective
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 57
Prerequisite and Recap
Prerequisite
• Different Problems like graph colouring
• Travelling Salesman Problem
Recap
• String Matching Algorithm
• Algorithms for solving real world problems
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 58
NP Completeness(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 59
NP Completeness(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 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
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 61
NP Completeness(CO5)
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:-
Although we can design a circuit and verified the mentioned output within
Polynomial time but remember we can never predict the number of gates which
produces the high output against the set of inputs/high inputs within a
polynomial time. So we verified the production and conversion had been done
within polynomial time. So it is NPC.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 62
NP Completeness(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 63
NP Completeness(CO5)
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
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 64
NP Completeness(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 65
NP Completeness(CO5)
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)}
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 66
NP Completeness(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 67
NP Completeness(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 68
NP Completeness(CO5)
• The salesman has to visit each one of the cities starting from
a certain one and returning to the same city.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 69
NP Completeness(CO5)
Proof
• In TSP, we find a tour and check that the tour contains each vertex
once.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 71
NP Completeness(CO5)
• 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.
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 72
NP Completeness(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 73
NP Completeness(CO5)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 75
Daily Quiz
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 76
Weekly Assignment
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]
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 77
MCQs
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 78
MCQs
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 79
MCQs
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 80
MCQs
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 81
MCQs
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 82
Glossary Question
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 83
Glossary Question
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
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 84
Glossary Question
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 85
Old Question Papers(2022-2023)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 86
Old Question Papers(2019-2020)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 87
Old Question Papers(2022-2023)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 88
Old Question Papers(2022-2023)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 89
Old Question Papers(2022-2023)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 90
Old Question Papers(2021-2022)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 91
Old Question Papers(2021-2022)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 92
Old Question Papers(2021-2022)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 93
Old Question Papers(2021-2022)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 94
Old Question Papers(2021-2022)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 95
Old Question Papers(2020-2021)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 96
Old Question Papers(2020-2021)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 97
Old Question Papers(2020-2021)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 98
Old Question Papers(2020-2021)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 99
Old Question Papers(2020-2021)
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 100
Expected Questions for University Exam
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 101
Recap Of Unit
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 102
Unit 5
Thank You
12/24/2024 Dr. Amba Mishra ACSE0501 Design and analysis of Algorithm Unit V 103