2 2 votes Algorithms algorithms made-easy-test-series quick-sort numerical-answers + – KISHALAY DAS 5.5k views answer comment Share Follow Print See all 9 Comments 9 9 Comments reply Show 6 previous comments S Ram commented Jan 16, 2017 reply Follow flag @srestha are talking abt 1st pass?? 0 0 replyShare srestha commented Jan 16, 2017 reply Follow flag yes , we have just choosen 15 as pivot. So, after applying quick sort, while 15 as pivot, we get elements are 12,11,13,14,15,16,18,17 So, only 12 is in previous position All other changes their position 0 0 replyShare hs_yadav commented Dec 19, 2017 reply Follow flag i think 6 is the answer if we use standard partition allgorithm.... 0 0 replyShare Please log in or register to add a comment.
Best answer 4 4 votes If I swap 15 with the last element, then 12 and 16 remain unchanged !! Then, total elements which change their positions are 6. If I swap 15 with the first element, then only 16 remains unchanged !! Hence, in this case the elements which change their positions are 7. This question is ambiguous as i think it should give the position. But if not given( like here ), i would go with the maximum .i.e, 7. As in both the case only 16 is constant by any method, we apply and all others (CAN) change their position means they are having the ability to change their positions . Hence I suppose , 7 should be correct . Kapil answered Nov 3, 2016 • selected Nov 3, 2016 by vijaycs Kapil comment Share Follow See all 2 Comments 2 2 Comments reply KISHALAY DAS commented Nov 3, 2016 reply Follow flag How 11 is getting swapped..could please post the image? 0 0 replyShare ManojK commented Nov 3, 2016 reply Follow flag https://gateoverflow.in/36401/quick-sort https://gateoverflow.in/19278/partitioning https://gateoverflow.in/27904/sorting 0 0 replyShare Please log in or register to add a comment.
3 3 votes 7 ans Anurag_s answered Jan 2, 2016 Anurag_s comment Share Follow See all 3 Comments 3 3 Comments reply priyanka1992 commented Apr 29, 2016 reply Follow flag if I swap 15(pivot) with the last element of the array(14), I am getting answer 6. 2 2 replyShare User007 commented Dec 9, 2016 reply Follow flag Why can't we keep 15 at last position and then apply partitioning algorithm? That way, answer will be different. 0 0 replyShare cse23 commented Jan 15, 2017 reply Follow flag even i m doing ame thing 1st i have swapped 15 with last element then applied partition hence getting 6 as answer 0 0 replyShare Please log in or register to add a comment.
2 2 votes Answer will be (7). nitish answered Jan 2, 2016 nitish comment Share Follow See all 5 Comments 5 5 Comments reply Show 2 previous comments nitish commented Jan 14, 2016 reply Follow flag change the position of pivot , if needed more clarification see the below comment. 0 0 replyShare Himani Srivastava commented Jan 14, 2016 reply Follow flag Below partitioning is fine when we take pivot as first element.. But if we take pivot as last element,Both 12,16 remain at their position 0 0 replyShare Sushant Gokhale commented Oct 21, 2016 reply Follow flag Even I am getting 6. I refered QUick sort algorithm video by mycodeschool.com - youtube. 1 1 replyShare Please log in or register to add a comment.
0 0 votes simply make one move in the beginning to swap the 15 to position from where u are comfortable to apply quick sort algorithm either at middle, first position or last. Abhishekcs10 answered Dec 14, 2015 Abhishekcs10 comment Share Follow See all 6 Comments 6 6 Comments reply Show 3 previous comments Abhishekcs10 commented Dec 14, 2015 reply Follow flag yes u have that value in a temporary variable but then after the partition loop the final step is to swap pivot element and (the position where smaller value pointer is + 1). but since you swapped it u either would have to take another variable to remember its position or do not move it at all. 0 0 replyShare Arjun commented Jan 7, 2016 reply Follow flag @Aspi You are right. I do not think "quicksort" enforces a "pivot" algorithm. It is up to implementation to do this. So, there is no fixed answer here- only the best case can be there. 0 0 replyShare Sara commented Jan 7, 2016 reply Follow flag Please tell me where i am wrong 1 1 replyShare Please log in or register to add a comment.
0 0 votes You have to choose 15 here as pivot element. The sequence becomes after first pass will be 12,11,13,14,15,17,16,18 nandini gupta answered Jan 16, 2017 nandini gupta comment Share Follow See all 7 Comments 7 7 Comments reply Show 4 previous comments S Ram commented Jan 16, 2017 reply Follow flag okay check that and correct me ... 0 0 replyShare nandini gupta commented Jan 16, 2017 reply Follow flag I think you are correct. Because elements 12,11,16 will not change their position. Are you also getting the same ? 0 0 replyShare S Ram commented Jan 16, 2017 reply Follow flag Yes i am getting same only... thtz why i have doubt.. how to consider answer here? 0 0 replyShare Please log in or register to add a comment.
0 0 votes Before partition Algo 12 18 17 11 13 15 16 14 After partition Algo 14 11 13 12 15 18 16 17 7 elements change their position Akash Mittal answered Dec 19, 2017 Akash Mittal comment Share Follow See all 2 Comments 2 2 Comments reply arch commented Dec 19, 2017 reply Follow flag how you getting 7 i am getting 6 after following algo given in clrs. first i swap last elemnet and 15 ie 14 and 15 then applied partition initial 12 18 17 11 13 15 16 14 final 12 11 13 14 15 18 16 17 0 0 replyShare Akash Mittal commented Dec 19, 2017 reply Follow flag i swapped with first element 0 0 replyShare Please log in or register to add a comment.