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

Join 131,724 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,307 people online right now. Registration is fast and FREE... Join Now!




Sorting Algorithm

 
Reply to this topicStart new topic

Sorting Algorithm, Just a question

oasisjoel
post 8 Oct, 2008 - 08:41 AM
Post #1


New D.I.C Head

*
Joined: 11 Sep, 2008
Posts: 38


My Contributions


In a topic www.wikipedia.org about sorting algorithm they say that
"Whether or not they are a comparison sort. A comparison sort examines the data only by comparing two elements with a comparison operator."

My question is "What if I use to compare more than two elements to sort, is it still classified as a comparison sort?"
User is offlineProfile CardPM

Go to the top of the page

homemade-jam
post 8 Oct, 2008 - 08:55 AM
Post #2


eeeAddict

Group Icon
Joined: 17 Mar, 2008
Posts: 1,039



Thanked 1 times

Dream Kudos: 25
My Contributions


Surely comparison is only between two things? More than two things would become a sort as they would form some sort of order
User is offlineProfile CardPM

Go to the top of the page

oasisjoel
post 8 Oct, 2008 - 09:04 AM
Post #3


New D.I.C Head

*
Joined: 11 Sep, 2008
Posts: 38


My Contributions


if more than two things how would it be classified?
User is offlineProfile CardPM

Go to the top of the page

baavgai
post 8 Oct, 2008 - 09:56 AM
Post #4


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,948



Thanked 94 times

Dream Kudos: 475

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


QUOTE(oasisjoel @ 8 Oct, 2008 - 01:04 PM) *

if more than two things how would it be classified?


Quantum? At the very least, theoretical. wink2.gif

Let's say I have three numbers, 5,4,3. I wish to sort them. Even though I have three items, when I compare, I still only compare two elements. The sort by hand would look something like this:
CODE

Starting list.
Pos    Value
0    5
1    4
2    3

Compare Pos0 to Pos1, if Pos0 is larger than Pos1, swap them.
Pos    Value
0    4
1    5
2    3

Compare Pos1 to Pos2, if Pos1 is larger than Pos2, swap them.
Pos    Value
0    4
1    3
2    5

Compare Pos0 to Pos1, if Pos0 is larger than Pos1, swap them.
Pos    Value
0    3
1    4
2    5


It may intuitively feel that you can compare more than two items at once, but when you break it down to individual operations, you're really doing it by pairs.
User is offlineProfile CardPM

Go to the top of the page

oasisjoel
post 9 Oct, 2008 - 09:14 AM
Post #5


New D.I.C Head

*
Joined: 11 Sep, 2008
Posts: 38


My Contributions


Hi guys can you help me.. What are the different advantage of using a sorting algorithm. Can you give me all its advantage from buss world to computer science world? Who benefits most when sorting algorithm is used??
User is offlineProfile CardPM

Go to the top of the page

nirvanarupali
post 9 Oct, 2008 - 09:07 PM
Post #6


D.I.C Foot

Group Icon
Joined: 1 Aug, 2007
Posts: 982



Thanked 2 times

Dream Kudos: 375
My Contributions


QUOTE(oasisjoel @ 10 Oct, 2008 - 01:14 AM) *

What are the different advantage of using a sorting algorithm.


The advantage is you can sort anything. blink.gif
User is offlineProfile CardPM

Go to the top of the page

oasisjoel
post 10 Oct, 2008 - 01:50 AM
Post #7


New D.I.C Head

*
Joined: 11 Sep, 2008
Posts: 38


My Contributions


I hope you understand my question well,,,

This post has been edited by oasisjoel: 10 Oct, 2008 - 01:50 AM
User is offlineProfile CardPM

Go to the top of the page

Gloin
post 12 Oct, 2008 - 05:22 PM
Post #8


On MeD.i.Cation

Group Icon
Joined: 4 Aug, 2008
Posts: 717



Thanked 46 times
My Contributions


Dunno if I understand you right but one huge benefit of sorting is when you operate on a huge set of data. Let's say you have 1,000,000,000 distinct numbers that you need to operate on. A good example is if you wanna find out if some (let's say 1,000) numbers are in that set.

If the numbers are not sorted, in worst case you'll have to go through approx. 1,000,000,000 * 1,000 numbers before you can give the answer.

If the numbers are sorted you only have to go through log(1,000,000,000) * 1000 numbers before you can give the answer which is substantially less (It's actually 30*1,000 = 30,000). The sorting would take some time (30*1,000,000,000) though but it's still much much faster.

That was really abstract but I guess anyone understands that handling
30,000,000,000 numbers is faster than handling
1,000,000,000,000 numbers

This post has been edited by Gloin: 12 Oct, 2008 - 05:53 PM
User is offlineProfile CardPM

Go to the top of the page

baavgai
post 13 Oct, 2008 - 02:52 AM
Post #9


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,948



Thanked 94 times

Dream Kudos: 475

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


QUOTE(Gloin @ 12 Oct, 2008 - 09:22 PM) *

That was really abstract ...


Perhaps a little. wink2.gif Put another way.

Let's say I have a value that I'm looking for in a sorted list. I start in the middle of the list and compare what I find there to my value. There are three possible outcomes of this one action. I find the value, I find a value larger than my value, or I find a value smaller than my value. Because the list is in order, I can now effectively ignore half my list.

This is the same as a number guessing game, which is why it's often offered to CS students as a problem. Pick a number between 1 and 100. Is it 50? Higher or lower? If you say lower, my next guess is 25. If you then say higher, my next guess is 32. In a list of 100 ordered values, it will never take more than eight guesses to find the answer. If I double the list size to 200, the effort it takes to find the number only increases by 1, and so on.

Hmm... don't know if that make more or less sense. tongue.gif
User is offlineProfile CardPM

Go to the top of the page

Gloin
post 13 Oct, 2008 - 11:47 AM
Post #10


On MeD.i.Cation

Group Icon
Joined: 4 Aug, 2008
Posts: 717



Thanked 46 times
My Contributions


Dunno if it does but maybe after reading both our posts some ideas will start to form.
What we're both referring to is one of the most well known (likely the most well known) algorithms that exist today, the binary search algorithm.

It lets you search through a set of n sorted values to find a specific value in logarithmic time. It's an extremely useful algorithm.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 10:11AM

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