Professional Documents
Culture Documents
نموذج فاينل
نموذج فاينل
VI. In Brute Force String matching, while pattern is not found and the text is not yet
exhausted, realign ________ one position to the right.
(a) Left (c) Right
(b) Pattern (d) String
X. In a Horspool’s algorithm, when searching a pattern with some text, if there is a mismatch occurs
Page 1 of 9
XI. Dynamic programming is a technique for solving problems with _________________ sub-
problems.
(a) Overloading (c) overriding
(b) Overlapping (d) operator
XII. In Tower of Hanoi puzzle to move 6 disc from peg1 to peg3 by using peg2 the number of
(a) 61 (c) 62
(b) 63 (d) 64
XIII. Quick Sort is a perfect example of a successful application of the __________________ technique.
(a) Brute Force (c) Divide & Conquer
(b) Decrease and Conquer (d) Dynamic Programming
XV. Analysis of algorithms means to investigate the algorithm's efficiency with respect to
Resources: like running time and __________.
(a) Speed (b) space
(b) Hardware (d) Input
SECTION – B (5 x 3 = 15 MARKS)
NP problem: NP: the class of decision problems that can be solved by nondeterministic polynomial (NP)
algorithms
NP Complete problem:
A decision problem D is said to be NP-complete if
1. It belongs to class NP.
2. Every problem in NP is polynomial reducible to D
Page 2 of 9
3. Explain Topological Sorting. Find the topological sorting for the following directed graph.
Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for
every directed edge uv, vertex u comes before v in the ordering. Topological Sorting for a graph
is not possible if the graph is not a DAG.
4. Write down the algorithm for closest pair problem. Also find the running time of the
algorithm.
Ans[ ]
Page 3 of 9
5.Consider the following recursive algorithm. (1 + 2 )
M(n) = [ M(n-2) + 1 ] +1
M(n) = [M(n -3) + 1 ] + 2
M(n) = M(n -3) + 3
. ….. ……
… i times ….. ….
……… .. … …..
M(n) = M(n -i) + i ------------------- (I)
M(0) = 0
So i = n in (I)
Page 4 of 9
M(n) = M(n -n) + n
M(n) = M(0) + n
M(n) = 0 + n
M(n) = n 𝜽(𝒏)
6. Find the running time of recurrence relation T(n) = 4T(n/2) + n2 using Master Theorem.
Ans[ ]
a= 4
b= 2
d=2
a bd
4 = 22
7. Using the Horspool’s Algorithm search the pattern BARBER on the following text
JIM_ SAW_ME_IN_ A_BARBERSHOP.
Ans[ ]
SECTION – C (2 x 5 = 10 MARKS)
Page 5 of 9
Answer any TWO Questions. Each Question carries FIVE Marks.
8. Apply Boyers-Moore algorithm to search for the pattern BAOBAB in the text
BESS_KNEW_ABOUT_BAOBABS.
Ans[ ]
9. Write the Warshall’s algorithm and apply it to find the transitive closure for the given
directed graph. (1 + 4)
Page 6 of 9
Ans[ ]
10. Write the Prims algorithm and also find the minimum spanning tree and cost of the following
Page 7 of 9
graph using Prims’s Algorithm.
(1 + 3 + 1)
Ans[ ]
Cost = ae + eb + ec + cd = 2 + 3 + 4 + 4 =13
Page 8 of 9
Ans[ ]
Page 9 of 9