Welcome to Dream.In.Code
Become an Expert!

Join 136,902 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,737 people online right now. Registration is fast and FREE... Join Now!




Computer Science Question

 
Reply to this topicStart new topic

Computer Science Question, Sorting

Ogre
17 Jul, 2008 - 07: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
+Quote Post

KYA
RE: Computer Science Question
18 Jul, 2008 - 09:34 AM
Post #2

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 5,001



Thanked: 118 times
Dream Kudos: 1200
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 online!Profile CardPM
+Quote Post

Einherjar
RE: Computer Science Question
18 Jul, 2008 - 11:26 AM
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 - 11:36 AM
User is offlineProfile CardPM
+Quote Post

Programmist
RE: Computer Science Question
18 Jul, 2008 - 12:26 PM
Post #4

Four-letter word
Group Icon

Joined: 2 Jan, 2006
Posts: 1,180



Thanked: 6 times
Dream Kudos: 100
Expert In: Java

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 - 12:46 PM
User is offlineProfile CardPM
+Quote Post

mattman059
RE: Computer Science Question
18 Jul, 2008 - 01:49 PM
Post #5

D.I.C Regular
Group Icon

Joined: 23 Oct, 2006
Posts: 340


Dream Kudos: 175
My Contributions
i personally like quick sort
User is offlineProfile CardPM
+Quote Post

KYA
RE: Computer Science Question
18 Jul, 2008 - 07:54 PM
Post #6

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 5,001



Thanked: 118 times
Dream Kudos: 1200
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 online!Profile CardPM
+Quote Post

Einherjar
RE: Computer Science Question
18 Jul, 2008 - 08: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
+Quote Post

NickDMax
RE: Computer Science Question
19 Jul, 2008 - 11:39 AM
Post #8

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,859



Thanked: 50 times
Dream Kudos: 550
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
+Quote Post

My_code
RE: Computer Science Question
22 Jul, 2008 - 04: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
+Quote Post

AmitTheInfinity
RE: Computer Science Question
22 Jul, 2008 - 04:20 AM
Post #10

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,026



Thanked: 35 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 offlineProfile CardPM
+Quote Post

skaoth
RE: Computer Science Question
21 Aug, 2008 - 12:12 PM
Post #11

D.I.C Regular
Group Icon

Joined: 7 Nov, 2007
Posts: 344



Thanked: 10 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
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 09:42PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month