43 43 votes What is the number of swaps required to sort $n$ elements using selection sort, in the worst case?$\Theta(n)$$\Theta(n \log n)$$\Theta(n^2)$$\Theta(n^2 \log n)$ Related Questions :GATE CSE 2006 | Question: 14, ISRO2011-14GATE CSE 2013 | Question: 6 Algorithms gatecse-2009 algorithms sorting easy selection-sort + – Kathleen 35.7k views answer comment Share Follow Print See all 6 Comments 6 6 Comments reply Show 3 previous comments Siddiqui_Danish commented Jan 1 reply Follow flag Bro Promototing GO's Opps 1 1 replyShare Siddiqui_Danish commented Jan 1 reply Follow flag In worst case scnearios 4 4 replyShare aashitagrawal commented Jan 2 reply Follow flag thanks! 0 0 replyShare Please log in or register to add a comment.
Best answer 46 46 votes The answer is A. In worst case, we have $1$ swap in each loop except the last one and hence $n-1$ swaps at max for $1$ to $n$. Therefore the worst case number of swaps is $\Theta(n)$ Gate Keeda answered Dec 10, 2014 • edited Dec 19, 2022 by Abhrajyoti00 Gate Keeda comment Share Follow See all 3 Comments 3 3 Comments reply reena_kandari commented Nov 28, 2017 reply Follow flag Best case: $0$ swaps. for eg $1,2,3,4,5,6$ Worst case: $n-1$ swaps for eg $6,5,2,1,4,3$ 25 25 replyShare Queenia Agrawal commented Jan 20, 2018 reply Follow flag @reena ma'am, it depends on implementation, but in its basic form, even in best case selection sort requires 1 swap in each pass. https://stackoverflow.com/questions/26688765/what-are-the-number-of-swaps-required-in-selection-sort-for-each-case 1 1 replyShare Manu Shaurya commented Jun 6, 2019 reply Follow flag A minor correction, in worst case , selection sort does n-1 swaps. 0 0 replyShare Please log in or register to add a comment.
16 16 votes option a abhishekmehta4u answered Mar 23, 2019 abhishekmehta4u comment Share Follow See 1 comment 1 1 comment reply ashutoshkpandey commented Oct 11, 2021 reply Follow flag Nice I confused in n2 and n. Now my confusion is clear thanks. 0 0 replyShare Please log in or register to add a comment.