User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,187 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,205 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 582 | Replies: 3
Reply
Join Date: Dec 2007
Posts: 5
Reputation: DoctorBob is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
DoctorBob DoctorBob is offline Offline
Newbie Poster

Algorithms

  #1  
Dec 6th, 2007
So I have 4 different algorithms to sort numbers that me and my best friends wrote to see who's worked the best. They are not the greatest ..since we aren't the greatest programmers..haha but we thought it'd be fun. I thought I'd let you guys take a look at them if you want! just for fun..haha I've attached them.


ohh and if any of you know anything about asymptotic notation is there any way you could figure what the notation would be for all four algs. attached..? If not thats fine but i'm interested in finding out so when we do compare them it would help. ..p.s. don't laugh to much! I'd really like some feedback on these algs. even though they probably aren't so great!
Attached Files
File Type: cpp Brian.cpp (2.3 KB, 7 views)
File Type: cpp Casey.cpp (1.9 KB, 7 views)
File Type: cpp Paul.cpp (5.4 KB, 6 views)
File Type: cpp Ron.cpp (2.1 KB, 5 views)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Location: UK
Posts: 468
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Rep Power: 5
Solved Threads: 42
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: Algorithms

  #2  
Dec 6th, 2007
There's no such thing as a "Best" sorting algorithm. Depending on the amount of data you're holding, and how ordered the data is to start with, one algorithm may be better than the other in different situations.


If you wanted to test them out against each another, you could devise a way profiling them, eg, by measuring the time they each take to sort an array of a million randomly generated numbers, or by sorting some pre-defined sets of data and checking the number of passes.

The results are likely to be inconclusive, since there is no "best" sort algorithm. Have a look at this list of different sort methods - http://en.wikipedia.org/wiki/Sorting_algorithm
Last edited by Bench : Dec 6th, 2007 at 6:38 am.
¿umop apisdn upside down?
Reply With Quote  
Join Date: Sep 2004
Posts: 6,333
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 28
Solved Threads: 458
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Algorithms

  #3  
Dec 6th, 2007
>to see who's worked the best.
That's going to be difficult even if you just stick to profiling. Two of the algorithms sort arrays and two of them sort linked lists, so the innate performance will be different even without the sort. A better test would sort only linked lists or only arrays for all of the algorithms.

>They are not the greatest ..since we aren't the greatest programmers..haha
They all seem to be unique creations (or at least somewhat unconventional), so props for that.

>is there any way you could figure what the notation would be for all four algs. attached..?
Why not use this as a chance to learn how to analyze your algorithms? Anyway, this is my initial take on the sorts after a quick glance:

Ron - This is a straightforward technique. Ron is running the linked list through a pre-sort filter that swaps values (only if needed) from the outside in. If a lot of swaps are made this will make the insertion sort step faster, and if a lot of swaps aren't made, the insertion sort would have been fairly quick to begin with. The filter (called a spiral patch) takes linear time and the insertion sort takes quadratic time. The sort as a whole is O(n^2).

Brian - This is really little more than an exceptionally inefficient selection sort. I'd call it O(n^2) + O(k) because both of those factors are equally devastating to the performance of the algorithm. Brian also needs to learn how to comment his code better.

Casey - Like Ron, Casey runs the array through a linear pre-sort filter. Casey then runs the array through a quick and dirty divide and conquer sort (which itself is a recursive linear filter), runs the array through the pre-sort filter again (maybe it should be a function if you use it more than once) and finally finishes off the algorithm with bubble sort. The algorithm as a whole is O(n^2), but the linear filters could make this a pretty zippy sort in practice. I don't think bubble sort was a wise choice for the finalizer.

Paul - Despite the comments, I'd say that this is more of a one step Shell sort than a merge sort variation. It's still O(n^2), but the result is likely to be faster than just running a basic insertion sort on the linked list.

Strictly from an asymptotic perspective, Ron, Casey, and Paul are all equal but Brian falls short. My guess is that Ron will be the most consistent overall, followed by Casey, then Paul, and Brian will still fall short in all of the tests. Casey and Paul will have niche areas that perform better than Ron, but probably not sufficiently better to determine a clear winner across the board.

Take these estimates with a grain of salt. I'm simply going on a 2 or 3 minute judgment of each program, and I didn't run any of them.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Dec 2007
Posts: 5
Reputation: DoctorBob is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
DoctorBob DoctorBob is offline Offline
Newbie Poster

Re: Algorithms

  #4  
Dec 6th, 2007
Wow thanks for the feedback. We actually are testing these algorithms with samples of 10,100,1000,5000,10000 and 15000 sets of random numbers..except for casey's as it is seeded by a random number generator.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 10:04 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC