Lost Password?

Go Back   CodeCall Programming Forum > Software Development > General Programming > Programming Theory

Programming Theory Discuss programming theory, algorithm efficiency, logic, and other any other category where math and computer science overlap.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-18-2008, 07:43 PM
John's Avatar   
John John is online now
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,345
Last Blog:
PHP Function Overloadi...
Rep Power: 50
John is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of light
Send a message via AIM to John
Default sorting efficiency

Under what circumstances would say, selection sort [ O(n^2) ], be more optimal than say, merge sort [ O(n logn ) ]?

Is it reasonable to thing of these as functions, thus for values of n where O(n^2) is less than O(n logn ) it is more efficient, and where O(n logn ) is less than O(n^2) it is more efficient?
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 01-19-2008, 11:46 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Mod
 
Join Date: Jul 2006
Age: 35
Posts: 1,751
Last Blog:
Game software (GURPS)
Rep Power: 24
WingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to all
Default

Because O() notation ignores a constant multiplier (and usually overhead for memory allocation/function calls), when n is small, the selection sort can actually be more efficient. For example, selection sort's efficiency might be 10 n^2 and merge might be 100 n log n. For n=2, that's 40 verses 60.

There are also times when you have to look at whether merge sort is *significantly* more efficient, given the addition coding time that may be involved.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-20-2008, 01:08 AM
John's Avatar   
John John is online now
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,345
Last Blog:
PHP Function Overloadi...
Rep Power: 50
John is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of light
Send a message via AIM to John
Default

So if you were just given the O() notation (without a constant multiplier or any information regarding overhead for memory allocation), it would be impossible to determine the exact amount of data for which each algorithm is more efficient?
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-21-2008, 12:29 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Mod
 
Join Date: Jul 2006
Age: 35
Posts: 1,751
Last Blog:
Game software (GURPS)
Rep Power: 24
WingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to all
Default

The purpose of O() notation is to measure which is more efficient for sufficiently large input. This relates to the idea of whether something will scale well. If one has efficiency 1000000x^2, and another has efficiency x^3, the second will perform better on small trials, but will not scale well to large trials.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-21-2008, 12:00 PM
CygnetGames's Avatar   
CygnetGames CygnetGames is offline
Programmer
 
Join Date: May 2007
Location: York, England
Posts: 113
Rep Power: 5
CygnetGames is on a distinguished road
Default Re: sorting efficiency

Another problem with just looking at time complexity is that in practice you may be concerned with space complexity as well. In functional languages, merge sorts are usually better for space than insertion sort, but in popular languages like C++ etc. implementing a merge sort usually requires more space than an insertion sort.

An example of when the constant multipiler is really important is with analogue computers. Using an analogue computer made of spaghetti it is possible to sort a list of numbers in linear time! (and linear space) But the problem is that it is such a task to actually build a machine that sorts using spaghetti. The constant multiplier is too high.

Also, if you know that your list is nearly sorted then insertion sort will do less work than merge sort. In my computer science course, we were advised to use insertion sort for small arrays. For medium-sized arrays, we were advised to start with quicksort but not take it all the way. If you stop a few iterations before quicksort is finished, you have a nearly-sorted array so it will be better to use insertion sort. For large arrays, shell sort was recommended. Not sure how widely-used these ideas are.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unique & Complex Sorting Program ryan.devani C and C++ 3 01-17-2008 12:28 PM
Help regarding the sorting of arrays with flags! Yuriy M C and C++ 3 10-12-2007 10:30 PM
Bubble sorting a list 0eraser C and C++ 1 06-13-2007 10:47 AM
Finding non-standard sorting order via graph theory elle General Programming 1 05-17-2007 09:36 PM
Sorting String ( Need help ASAP) Gordack C and C++ 4 04-20-2007 11:12 AM


All times are GMT -5. The time now is 05:15 PM.

Contest Stats

John ........ 87.50000
dargueta ........ 75.00000
Xav ........ 50.00000
MeTh0Dz ........ 20.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000

Contest Rules

Ads