Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sorting alogorithm

Posted on 2011-03-01
5
Medium Priority
?
963 Views
Last Modified: 2012-05-11
Please tell me which sorting algorithm is most efficient when the data:
1. has very few unique elements
2. is in reverse sorted order.

Also, please tell me the complexity in each case.

Thanks!
0
Comment
Question by:dshrenik
5 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 35012615
Come on. This is homework. Go read up on Big O notation and binary trees. 20 minutes of light reading and you should be able to figure this out.

Here: http://warp.povusers.org/SortComparison/
0
 
LVL 20

Expert Comment

by:edster9999
ID: 35012633
Read something like this :
http://en.wikipedia.org/wiki/Sorting_algorithm

If you need more detailed info you will have to provide sample data or more information.
The question sounds a bit like an exam or homework question.  if this is the case you are supposed to specify that.
0
 

Author Comment

by:dshrenik
ID: 35012654
Its not a homework problem. I'm preparing for an interview.
I'm trying to identify the best algorithm for various scenarios:
When values are in a small range - Bucket sort
Nearly sorted - Insertion sort, etc.
0
 
LVL 20

Expert Comment

by:edster9999
ID: 35012782
As above the links tell you all there is to know about sorting.   The formulas give you the rough time / memory / number of steps it takes to sort the field as the size etc increases.
You need to understand the idea of things like 'the big O'
If you understand that and you are able to code the basic sort functions then you can talk about it in an interview.
read, read, read....
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 2000 total points
ID: 35014010
If it's in reverse sorted order, then just flipping it is best. Time complexity is O(n). You could implement some kind of 'groupsort' than keeps all the same elements together.
For the traditional algorithms, you won't get better than O(nlg(n)) anyway. But if you do 'groupsort' you could get O(n + mlg(m)) where m is the number of unique elements.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of Google's most recent algorithm changes affecting local searches is entitled "The Pigeon Update." This update has dramatically enhanced search inquires for the keyword "Yelp." Google searches with the word "Yelp" included will now yield Yelp a…
Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question