How to do stable sorting by selection sort? Here is some input like this => 38, 34b, 36, 34a, 1 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to do stable sorting by selection sort? Here is some input like this => 38, 34b, 36, 34a, 1

How to check which comes first 34a or 34b

25th Aug 2019, 9:55 AM
Preity
Preity - avatar
6 Answers
+ 5
~ swim ~ Based on Preity mentioning stable sorting, it might be the case where the a and b next to 34 are not actually visible. I think what Preity is trying to ask is how are we supposed to know which 34 comes first and which comes second if we claim that our selection sort algorithm is stable. That said, it's a little confusing based on their follow-up query. I'll just leave my interpretation of the query here.
25th Aug 2019, 11:25 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
~ swim ~ Yeah, in classes, we were taught to handtrace. Can't think of a way immediately either. ... Reference variables, maybe? 🤔
25th Aug 2019, 11:39 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Hatsy Rei your interpretation is correct that's why I make tag of stable selection sort @hatsy and ~ swim ~ sorry for confusion. Yes I've talking about stable sorting and a and b is just invisible for understanding that two different key member with same value are present. So how can I decide which one to take first any way to do that with help of references then how?
25th Aug 2019, 12:04 PM
Preity
Preity - avatar
+ 2
~ swim ~ I'm not used that function before will try for that thanks. But stable sort function in STL is used merge sort as an working procedure. So can't we make some logic as used in merge sort by any divide and conquer technique or any dynamic programming and back tracking A sorting algorithm is said to be stable if two objects with equal keys appear in the same order in sorted output as they appear in the input array to be sorted. So does you guys indicating towards storing the address of input sequence with similar key value and then match that address at sorted result and know if they are at same place as input or not
25th Aug 2019, 12:45 PM
Preity
Preity - avatar
+ 1
~ swim ~ OK I'll look over those thank you
25th Aug 2019, 5:38 PM
Preity
Preity - avatar
0
~ swim ~ can you help me to know how to sort when number and character both are their on input by selection sort?
25th Aug 2019, 10:11 AM
Preity
Preity - avatar