Awesome q2a theme
0 votes
47 views

Question – In the best case, what is the minimum number of swaps are possible using Selection Sort Algorithm?

My Take – Best case –> means can we take input array as best case is mentioned – like already sorted Array (ascending or reverse sorted) array in both cases Selection Sort makes zero swaps i.e Ɵ(1) 

But I remember Arjun Sir once mentioned that – Best case for worst case Input. So, should we take unsorted array and like 213 and say minimum number of swaps selection sort can make is Ɵ(n)

Please help, I’m kinda confused.

in Algorithms by (83 points) | 47 views
0
What do you "want" to mean by best case for worst case input? Cases are obviously for inputs afaik.
+1
When the array is sorted, the number of swaps→ O(1)

When unsorted → O(n)
+1
No matter whether the array is sorted or not but selection sort has to compare the element $e_i$ with all the elements of the array. So this comparison goes as like

= (n-1) comparision for $1^{st}$ element + (n-2) comparison for $2^{nd}$ element + $\dots + 2+1$

= $O(n^2)$

but number of swap will vary, as in best case it will be $O(1)$ but in worst case it will be $O(n)$ and when we find the complexity of sort so we have to consider both $\text{number of comparision + number of swaps}$

Please log in or register to answer this question.

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
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.
Top Users May 2020
  1. Kushagra गुप्ता

    97 Points

  2. praveen modala

    15 Points

  3. ramcharantej_24

    15 Points

  4. abhishek tiwary

    12 Points

  5. srestha

    12 Points

  6. Dtiwari

    9 Points

  7. Shivateja MST

    8 Points

  8. ankitgupta.1729

    8 Points

  9. Rashimdixit

    7 Points

  10. Bhavya1902

    7 Points

7,376 questions
1,741 answers
10,682 comments
90,352 users