Solved

Sorting alogorithm

Posted on 2011-03-01
5
950 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 500 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This algorithm (in C#) will resize any image down to a given size while maintaining the original aspect ratio. The maximum width and max height are both optional but if neither are given, the original image is returned. This example is designed t…
Okay. So what exactly is the problem here? How often have we come across situations where we need to know if two strings are 'similar' but not necessarily the same? I have, plenty of times. Until recently, I thought any functionality like that wo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now