Greedy Method _ DPP 01 Discussion Notes
Greedy Method _ DPP 01 Discussion Notes
ENGINEERING
Algorithms1
Greedy Method
A 680 Ans
B 700 pirot 121
C 720
if 3818110 160
someday an n
180 19
8
D 740
G G i n
5 3
5 3
51 3
Total orderings
5 4 3 247 6
120 6
1729
[MCQ]
#Q. Let T(n) = [n(log(n3) – logn) + logn]n + logn, complexity of T(n) is
mm
A 2
O(n ) Tn n log in3 loan logn n
B O(n3) t logn
C O(nlogn)
A 109 B
09
D
AIB
2
O(n logn)
109
AM
log n n logn
Tin n log
if
n logn n log n
nA log
2n log n logn n logn
log n
12m log n n logn
T term
dominating
n O 2m logo
Tn 1ognM
0 n
[MCQ]
m
A 2n – 3
C mergingconcept
D Ans
Merest
BD
A m
DI
Bestcast
no
of
Comparisons
n min In m
O
of comparisons
tfti
no
n m 1 exact value
Total elements 4
Sold
I
My
I
1 4 1 TEA ⁿ
1 MY
I
I
1
Is
It 11 b
No paisonsinworsteasl.is
final ans
1 n 1
1 n
12
2 2 In 1
2
n l
D 2
3
2
[NAT]
#Q. Consider the number in the sequence
2 5 11 17 19 21 26 33 39 40 51 65 79 88 99
Using binary search, the number of comparisons required to search
elements ‘2’ is____
Ans
key Z
2,526 039 no 5106549 889kg
E
Pyst Low 0 High 14
0
mid Lloyd
A 7 33
A mid
2 7 mid
key 2 key
explore
left
High mid I
7 1
Pass 2 0 High 6
Low
L 3
mid Ish
Asmid A 3 11
A 3 key
explore
left
High mid
I
3 1 2
Pass Low 0 high 2
mid 10 494 1 21 1
A I 5 7
A mid key
explore
left
mid I
High 0
1 1
P 0 High 0
Low
0
mid 11 9
A 800
no
Grains y
exact value
B 400
799
C 200 1597
D 100
so 1347 Ans 13470
Sol 50
600 100 250
2 smallest files
Logic Always pick
ntm
Resultant size
put it back
to list
individual
and remove the
n m size files
15 250400 400
150
400 1
T.IE
sorted
final
800 1
file
Total 149 399 799 113472
[NAT]
#Q. Consider a machine which needs a minimum of 50 seconds to sort 500
names by quick sort, then what is the minimum time required to sort 50
names (approximately)is _____ (round off to 2 decimal)
Ans 3.14
Quicksod
Soot
min Time 50sec 500 Clemests
ems Time
Sort
To sort tents
Gair
or
units time
Best care
O n logn of
is
O n2
worst case
Case
Minimum time Best
n Ifsec
units 50sec
5004 log 1500
I see
1mi 9500
Read 150
elements
Time read to sort 50
units
50 109,50
50 109
1 1092500
[NAT]
#Q. What is the total number of comparisons that will be required in worst case
to merge the following sorted files into a single sorted file into adsingle
sorted file by merging together two files at a time____.
e
Files F1 F2 F3 F4
Number of records 40 42 44 46
90 424446
Ans 34T
2
Based on
way merging pattern
disussed earlier
Sofni.given4042444
tm
174042444
G
FY.IE
sorted
172 1
final
file
in we
Comparisons
Total no
of
82 1 90 1 172 1
82 344 3
90
2
31
II
THANK - YOU