in GATE retagged by
616 views
0 votes
0 votes

We write a new algorithm by considering the fact that number of comparisons required by Selection Sort can be reduced by considering elements in pairs and finding the minimum and maximum element at the same time.

What will be the time complexity of the new algorithm for comparisons of Selection Sort?

  1.    $O/2$
  2.    $O(n)/4$
  3.    $O(n)$
  4.    $O$$(\log n)$
in GATE retagged by
by
616 views

2 Comments

options are not clear.
1
1
Selection sort usually takes $\frac{n^2}{2}$ comparisons.

I believe by taking pairs, we'll reduce the comparisons by a factor of 2 (ie $\frac{n^2}{4}$)

This is still $O(n^2)$

 

What did I miss? :(
0
0

1 Answer

1 vote
1 vote
Best answer
The new algorithm will only reduce the number of comparisons but will not reduce the complexity.
selected by

9 Comments

so should the complexity not be O(n^2) where as the number of comparison are O(n)?
1
1
No , complexity will be same .
0
0
Sir,

will the factors /2 and /4 in options A and B be absorbed by the O notation and eventually become  O(n) right ?
0
0
yes, right, they will eventually become  O(n)
1
1
@bikram sir
Is it asking for the time complexity of comparisons or the selection sort as a whole, its not clear in the question. Beacause if it's asking time complexity of selection sort, shouldn't it be O(n^2)?
1
1

yes, it is asking for the time complexity of comparisons of selection sort only. And not the selection sort as a whole ( which have O(n2) time complexity ) 

For selection sort, number of comparison is O(n) , read https://www.macs.hw.ac.uk/~pjbk/pathways/cpp2/node67.html

0
0

Bikram sir

no of comparisions will be O(n2).

So why we are getting time complexity of O(n)?

Also according to the provided link above https://www.macs.hw.ac.uk/~pjbk/pathways/cpp2/node67.html

1
1

@kash0611

The screenshot you posted doesn't mention about the modification being done here in the question. This is the unmodified version right..?

Also the link is broken..

@Bikram Sir, please elaborate a bit..

0
0

@Bikram Sir, Can you please elaborate how the element pair will reduce the comparison complexity (by taking any example) because I think that even if we take pair we will still need each element to compare with the current_max and current_min element , which would make the comparisons same.

my thinking may not be correct, so please correct me !

@GO_user

0
0
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

64.3k questions

77.9k answers

244k comments

80.0k users