Professional Documents
Culture Documents
)
i
EHIOCOIERRUSSVTS
©
Only case 3 and § ensures O(n log 7) time
complexity always.
Case 1: Choosing middle element doesn't mean
that pivots location isin middle, after the partition
algorithm. In worst case pivot may go either fist
cor last location (O(r?). Similarly Case 2, Case 4
Goes not guarantee O(nlog n).
But cases 3 and 5 ate similar and makes sure
that pivot always goes to middle location, after
the partition algorithm,
(720)
‘We have to choose first element as pivot.
Here 60 js given as frst elemont.
Attar first pass, the pivot element goes to its
exact location.
Here 60 goes to 6" place.
Allthe elements less than 60 go toleftof 60 and
all the elements greater than 60 go to right of 60.
Alter 13 pass
s 18 7 12
38 69 80 9 95
os “SS
s 3
= 51x31
= 720 possible arrangements.
(169)
Given fil
20.21, 22, 23) 41-1
1, 22.23) 45-1
40 comparisons
44comparisons
85 comparisons
40444485 = 169
Objecive Pcie Sts13.
14,
15,
16.
GF obiective Practice sets
| Computer Science & IT
(400)
‘Two sorted file of size mand n take Om + 1)
time for merging so total time = 200 + 50 + 125
+25 = 400
(c)
Insertion sort in best case = O(n)
land bubble sort = O(r?); selection sor
merge sort = O{n log n)
(b)
In the best case quick sort algorithm makes
‘nog (n) comparisons. So 1000 x log (1000) =
9000 comparisons, which takes 100 sec. To sort
100 names a minimum of 100 (log 100) = 600
comparisons are needed,
This takes 100 x 600/900 = 6.7 sec.
(b)
Pass as we
GD GD ED
oe
S
a w
i A 1207
Hence (b) s the correct option
Ered 2078)
17,
18,
19,
QgMabE ERsy
3S mMApdeE EAsy
(a)
In linear or sequential search the maximum no.
of comparisons are (n) for n elements hence the
‘no. of comparisons when the elemento be found
the middle of the array
n+ 12 if nis odd]
= 12 [if nis even]
in general average cast
Hence (a)/s the correct option,
@)
3 way merge sort will combine 3 subarrays at a
time, After division elements becomes,
ae
f 7055 wT 2 13 77 82 50
fei ded tea d
5) 70/60) [71|72| 00) (s2|73|77] [50
(b)
Divide the elements into nik groups of size k
and sort each piece of Ok log 4) time. This
preserves the property that no element is more
than k element out of position. Now merge each
block of k elements with the block to its lft.
wiwmadecasy.inu
Tray
Q.1 Assume that letters p, 9, r, 8, tand u have
probabilities
respectively. What is the average length of the
message using Huftman's coding?
Q.2 Consider the following graph
STEEL
Greedy Techniques
message A, B, C, D, E.Theleft and right branch
of the tree is interpreted as 1 and 0 receptively.
The distance of the external node is counted as
bit sequence in decimal from the root node.
Then, what will be expected decode time if
message transmitted is DBACABEED?
=
On
‘a
Oc
e “D
(@) 9 units (©) 3t units
(©) 45units (@) 68units
Find which of he folowing edge isnever usedto 8 Which of the folowing is tue about Huffman
‘compute the shortest path from single source(M) etman cading mey become k 7
to every other vertex using dijkstra’s algorithm. (@)_Hutfman coding may become lossy in some
ea Gen 1 en como coestn
(©) (A, 8) (SY) luffman coding le Is prefix of any
ather code
Q.3 Find the running time of dikstra’s algorithm on (6) Huffman codes may not be optimal lossless
complete graph of r-vertces. codes In some cases.
@ an (b) OU?) (@ Allotthe above
(©) OrPiogn) ——_d) Or)
Q.7 Find the maximum possible value for fractional
Q4 Consider the following instance of knapsack Knapsak problem?
Problem. tem [ato elale h 7
Wem [ [2 | [fm | Weight [3 |S] 2| 1] 12/1) 9|o]4| 1
Pott [ts [wa] 9 |e [7 vaue [7b w0 3 [3 [ae] vol val ts |e
[Weal 2 [sts tate Knapsack capacity (Wi) = 20.
The maximum weight of 12 is allowed in the
QB Given a set A=(A,,A,.... Aj of a acivities
knapsack. Find the value of maximum profit with
the optimal solution of the fractional knapsack
problem,
(@) 31 (0) 402
(© 485 (2) None of these
Q.5 Consider the following decode tree (Called
Huffman codes) corresponding to codes for
with start and finish time (Sif), 1