Sorting Algorithms - DPP 01 Discussion Notes
Sorting Algorithms - DPP 01 Discussion Notes
ENGINEERING
Algorithms
Sorting Algorithms
B
P
T P T n
2
2
PX Inspect
P
C T P 2T n Incoods
2 PX Best case Ofp
P
D T P 2T O 1 worst lane 0
2 p
option A Tlp T 011
Plz
T P2 1
TIP 2 TIP 22 I
T P 22 2
TIP
T
1
P 23 3
i 2 P
p T P 2 k
k log I
T i
log
O 1091
B T p T P2 p
OI
9 1 bÉ2 f p p
0
109,9
p
C TP
Bestan
TCP 2 IIP 2
P 2 2T P P
P 22 2
2
22T P 22 I P
T P 22T P 22 PTP
22 T P 22 2P
23T P 23 3P
General Term
T p 2 T P 2k KAP
for B C Plak I
2K P K log
ftp.olplogp
1
D P a
1
2T P 22 I
TIP 2
2 2T 7 22 1 I
T P
22T 8 22 2 1
23T P 23 22 2 2
term
Gamal
TIP 2 T P 2K 2 21 2
GP 9 1
Sam
r a af
F K
2k 1
General Term
For B C Plak I 2k P
1k
109I
P T 1 P 1
TIP
PAC P I
IOIPD
[NAT]
#Q. Consider the following A with 8 elements:
60
What is the index value of elements after 3 rd pass of selection sort?
a
Ami
Ilp 70 602050 4050 19 21
pad 0 5 6 50407019 21
p
50 4070 60 21
5 19
pass20 p
210
pass 301ps
5 19 20 50,6 6
2
20 70 60 50
40 5 19 21
pass p
pass 50 p 5 19 20 21 40 70 60500
20 21 40 50 70
pass 60
p 5 19
2021 40 50 60 to
pass
70
p 5 19
n 1
passes always
[MCQ]
#Q. Consider the following array with 8 elements
50 60 90 65 55 45 85 12
A 50, 60, 55,45, 12, 65, 85, 90 B 12, 45, 50, 60, 90, 65, 55 85
C 90, 85, 65, 50, 60, 55, 45, 12 D 50, 55, 45, 60, 12, 65, 85, 90
E may
last 3
Ans 3ʳᵈ pass
I elent
sorted
4585 12
Given 50 60 90 65 55
In 45 85 12 90
50 60 65 55
past.io p
12 90
20 50 60 55 45 65
pass p
45 60 12 650085900
30 p 50 55
pass
50 45 55 12
650850900
puss p
pass 50 p 4550 12
550
I n 60 65 85 90
12 50 55
pass 6 0
p 45
60 65 8590
45 50 55
pass 0
p is p
F n 1
passes
sorted
[NAT]
Numerical Ans
#Q. Consider the following array A with 9 elements
unsorted
s
60 70 65 55 25 15
given Input 10 20 50
To
a 65 55 25 15
pass 10 50 60 70
swaps
A
70 65 55 25 15
pass2 10 20 500 60
A swaps
10 20 50 060 70 65 55 25 15
pass
swaps
pussy 10 20 50 60
00 65 55 25 15
swaps
sorted
Total swaps 0 53 5 7
16 swaps
[MSQ]
#Q. Bubble sort is-
AM
AI
not in place
oldspace
A In place sorting technique B Outplace sorting technique
Stable Inplace
[MCQ]
#Q.
0
What is the time complexity of selection sort in best case, average case and
work case respectively is:
AM B n Aln Wen
B O(n), O(n )
2 , O(n )
2 worst case 0 ny
C O(n ), O(n ),
I O(n )
2 2 2
Comp Swaps
Selection Sort 01m
Always
[MCQ]
#Q. Consider the following elements:
101 56 934 555 8 12 785 23 5 999
radix Sort
B 56, 23, 12, 8, 5, 101, 55, 785, 999, 934
non comparison
555
C 6
5, 8, 12, 23, 56, 101, 555, 785, 934, 999
g
D 5, 8, 12, 23, 56, 101, 555, 785, 934, 999
bucket
Ans
56 785 23 5 999
A 101 934 555 8 12
1
4 5 5k
Pass Bucket as
per last digit IIfromRght
5
785
555 56 8 999
101 12 23 934
YUUU
44444W
8 9
O
1 4,55
to
1 12 13 65 to do 88
Bucket 2ⁿᵈ last digit 2ⁿᵈ digit from
Past as
per right side
5 05 0
8 8 08
5 56
101 12 23 934 555 785 999
UNW
O 2
Y.FHWYH.WH.VN
sorted 9910
Pass 30 p
101 555,785 934 999
5,812,2356
Lectures
I
DPP WT
µ
Practice
THANK - YOU
PYO