user65165
user65165

Reputation: 974

Sorting Algorithm conundrum

I have been exposed to a lot of sorting algorithms lately: from bubble sort to radix and counting sort, but there is a particular problem for which I do not know what is legal to do or not. (I'm still in the pseudo-code writing phase, so I am not yet writing the algs in code languages and running tests- thus my security about what is 'legal' and what is not, is kinda shaky.)

The problem is about sorting a list of intervals with respect to the start-point: for example: sorting List1 = [[1,4] , [7, 17], [5, 10]] For the particular algorithm I've designed, I need them to be sorted into something like: [[1,4] , [5, 10], [7, 17]]

I thought of doing radix sort backwards, but I read that radix sort is specifically for digits ordering. It does look like I could use bucket sort too, but we didn't learn about bucket sort in class...

Edit1: There is a time efficiency i need to worry about, so that's why I'm not doing the most straightforward solution and compare all List1[i][0] for i in range(list1)

Upvotes: 0

Views: 158

Answers (1)

Yawar
Yawar

Reputation: 355

I suppose that the interval start points can be any real numbers, in that case I would advise you to use a Comparison based sort (insertion,selection,bubble,merge,heap,or quick) instead of Distribution sort (radix, counting or bucket). Though comparison based sorts have a lower bound of O(nlogn) but they can be used in any general case as compared to O(n) sorts like counting/ bucket which require input to be in some specific range.

Upvotes: 1

Related Questions