0% found this document useful (0 votes)
10 views26 pages

Sorting Algorithms - DPP 01 Discussion Notes

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views26 pages

Sorting Algorithms - DPP 01 Discussion Notes

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

CS & IT

ENGINEERING
Algorithms
Sorting Algorithms

DPP - 01 Discussion Notes By- Aditya sir


[MCQ]
IMPO
#Q. What is the recurrence relation of insertion sort when the array is almost
sorted with p element?
T
P
1091 Bestas
T  P   T    O 1 D
A  
2 1 AM

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

TIP PAT 1 PA log I


PAC PA 1099

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

TCP 2kt Pak 24 1

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

What is result after 3 rd pass of bubble sort?

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

How many swaps are nelded


e to sort the array by using insertion sort ?

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

pass 5 10 20 50 60 70 650 55 2515


swaps
6 10 20 50 60765 70
055 25 15
pass
swaps
155
7
10 2 555.56 6.570 5
5 swaps
pass m n
m 65
m 60 7.0
8 10 20 25 5055
pars swaps
20 50 55 60 65 70
Op 10 15 25
Δ

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

C Unstable sorting technique D Stable 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

A O(n), O(nlogn), O(n )


2
Best case 1 n2

B O(n), O(n )
2 , O(n )
2 worst case 0 ny
C O(n ), O(n ),
I O(n )
2 2 2

D O(n) , O(nlogn), O(nlong)


10in
Always 0 n2
[MCQ]
#Q. How many swaps and needed in selection sort to sort n element in worst
case?
takes min swap
Among all
Am
n  n  1 comp algos
A n –1 B we
2 in
C n D n 2

Comp Swaps
Selection Sort 01m
Always
[MCQ]
#Q. Consider the following elements:
101 56 934 555 8 12 785 23 5 999

What is the result after 3 rd pas of padix


8 sort?

A 56, 23, 12, 8, 5, 101, 555, 785, 934, 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

sass 555 56,785,99


20
pi 101 5 8 12
23,934
I I to Is to Ia
9
I 0 0

pass Bucket as per 3ʳᵈ digit from right side

1005 place dig


56 5 005
23 127012
12 999
555 785 934
101

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

You might also like