Welcome to Dream.In.Code
Getting Help is Easy!

Join 109,558 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,380 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Computer Science Question

 
Reply to this topicStart new topic

Computer Science Question, Sorting

Ogre
post 17 Jul, 2008 - 08:29 PM
Post #1


New D.I.C Head

*
Joined: 3 Jul, 2008
Posts: 10


My Contributions


I was watching a vid on Youtube where Eric Shmidt of Google asked Barack Obama, "what is the most efficient way of sorting a million 32 bit integers," and I'm curious to know what the answer was because Obama only said the "Bubble Sort" wasn't the most efficient way.

Just to give this thread a bit more substance, I would like to know more about this bubble sort from you guys.
User is offlineProfile CardPM

Go to the top of the page


KYA
post 18 Jul, 2008 - 10:34 AM
Post #2


#include <nerd.h>

Group Icon
Joined: 14 Sep, 2007
Posts: 2,932



Thanked 22 times

Dream Kudos: 1150
My Contributions


Depends I suppose. Bubble sort is faster when the list is smaller and more prone to be in order to begin with. Other choices to sort the list include insertion sort or merge sort.
User is offlineProfile CardPM

Go to the top of the page

Einherjar
post 18 Jul, 2008 - 12:26 PM
Post #3


D.I.C Head

**
Joined: 10 Feb, 2008
Posts: 73


My Contributions


QUOTE(KYA @ 18 Jul, 2008 - 01:34 PM) *

Depends I suppose. Bubble sort is faster when the list is smaller and more prone to be in order to begin with. Other choices to sort the list include insertion sort or merge sort.


From performance tests, and I could be remembering this wrongly, that quick sort is, as the name implies, usually the fastest sort you can do, especially with larger sets of numbers.

Edit: I guess I should also note however, that the quick sort has some worst case scenarios. Specifically when the list in in order or in reverse order. In these cases merge sort and heap sort, I believe, are actually faster.

This post has been edited by Einherjar: 18 Jul, 2008 - 12:36 PM
User is offlineProfile CardPM

Go to the top of the page

Programmist
post 18 Jul, 2008 - 01:26 PM
Post #4


Four-letter word

Group Icon
Joined: 2 Jan, 2006
Posts: 1,085



Thanked 4 times

Dream Kudos: 100
My Contributions


The question is very general, so I'm assuming we're talking about a simple sort with no requirements on insertion, deletion, or search times. If I'm sorting around 10 or fewer, I'll use insertion sort. If more than 10 and there are no strict memory limitations, I typically go for merge sort. If there are memory limitations then I might use heap sort or possibly quick sort.

This post has been edited by Programmist: 18 Jul, 2008 - 01:46 PM
User is offlineProfile CardPM

Go to the top of the page

mattman059
post 18 Jul, 2008 - 02:49 PM
Post #5


D.I.C Regular

Group Icon
Joined: 23 Oct, 2006
Posts: 337



Dream Kudos: 175
My Contributions


i personally like quick sort
User is offlineProfile CardPM

Go to the top of the page

KYA
post 18 Jul, 2008 - 08:54 PM
Post #6


#include <nerd.h>

Group Icon
Joined: 14 Sep, 2007
Posts: 2,932



Thanked 22 times

Dream Kudos: 1150
My Contributions


QUOTE(Einherjar @ 18 Jul, 2008 - 12:26 PM) *

QUOTE(KYA @ 18 Jul, 2008 - 01:34 PM) *

Depends I suppose. Bubble sort is faster when the list is smaller and more prone to be in order to begin with. Other choices to sort the list include insertion sort or merge sort.


From performance tests, and I could be remembering this wrongly, that quick sort is, as the name implies, usually the fastest sort you can do, especially with larger sets of numbers.

Edit: I guess I should also note however, that the quick sort has some worst case scenarios. Specifically when the list in in order or in reverse order. In these cases merge sort and heap sort, I believe, are actually faster.


Of course, I was only mentioning a few off the top of my head. Parameters to the problem dictate what sort or search method to use.
User is offlineProfile CardPM

Go to the top of the page

Einherjar
post 18 Jul, 2008 - 09:30 PM
Post #7


D.I.C Head

**
Joined: 10 Feb, 2008
Posts: 73


My Contributions


QUOTE(KYA @ 18 Jul, 2008 - 11:54 PM) *

QUOTE(Einherjar @ 18 Jul, 2008 - 12:26 PM) *

QUOTE(KYA @ 18 Jul, 2008 - 01:34 PM) *

Depends I suppose. Bubble sort is faster when the list is smaller and more prone to be in order to begin with. Other choices to sort the list include insertion sort or merge sort.


From performance tests, and I could be remembering this wrongly, that quick sort is, as the name implies, usually the fastest sort you can do, especially with larger sets of numbers.

Edit: I guess I should also note however, that the quick sort has some worst case scenarios. Specifically when the list in in order or in reverse order. In these cases merge sort and heap sort, I believe, are actually faster.


Of course, I was only mentioning a few off the top of my head. Parameters to the problem dictate what sort or search method to use.


Ah yes, I actually meant to quote the OP's post, and not yours smile.gif Oops.
User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 19 Jul, 2008 - 12:39 PM
Post #8


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,756



Thanked 34 times

Dream Kudos: 525
My Contributions


Well you can start by looking at this comparison chart.

I have found that people like the quick sort. It is very popular but in technical applications you tend to see a preference for the merge sort.

with modern applications you may see concurrent algorithms used. These are generally derivatives of the quick sort or merge sort. While they may be "faster" they generally require the same number of comparisons and are therefor not really "more efficient".

Comparison searches can be no better than O(n*log(n)).

There are other specialized sorting algorithms which may be more efficient given some information about the data being sorted. A Radix sort for example has the potential to be very efficient for specialized situations.

Here is another good comparison of some sorting algorithms (as well as a nice list -- though not complete).
User is offlineProfile CardPM

Go to the top of the page

My_code
post 22 Jul, 2008 - 05:09 AM
Post #9


New D.I.C Head

*
Joined: 10 Jul, 2008
Posts: 13

If the list is small then buble sort is good.

but i prefer quick sort. it is the quickest sorting method with efficient time and space.
User is offlineProfile CardPM

Go to the top of the page

AmitTheInfinity
post 22 Jul, 2008 - 05:20 AM
Post #10


D.I.C Addict

Group Icon
Joined: 25 Jan, 2007
Posts: 560



Thanked 10 times

Dream Kudos: 125
My Contributions


QUOTE(My_code @ 22 Jul, 2008 - 05:39 PM) *

If the list is small then buble sort is good.

but i prefer quick sort. it is the quickest sorting method with efficient time and space.


Quick sort can be as fast as Merge sort [it is as fast as and not faster than Merge sort] but it's performance is not stable (goes up to O(n^2) in worst cases). Where as Merge sort is stable on performance O(n*log(n)). There are also few memory saving tricks for Merge sort. So I prefer Merge sort.
User is online!Profile CardPM

Go to the top of the page

skaoth
post 21 Aug, 2008 - 01:12 PM
Post #11


D.I.C Regular

Group Icon
Joined: 7 Nov, 2007
Posts: 323



Thanked 5 times

Dream Kudos: 100
My Contributions


As NickDMax points out there are special sorts out there that provide more efficient searching than say quicksort, but these are not comparison based search algorithms.

I suspect that radix sort or bucket sort is the answer Eric was looking for.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/7/08 11:16PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month