Not logged in

Please login with username, password and session length or register.


Advanced search  

Author Topic: Algorithm Analysis  (Read 23851 times)

lavakill

  • RenX Game Leader
  • Staff
  • Medium Tank driver
  • ******
  • Offline
  • Posts: 533
Algorithm Analysis
« on: August 17, 2013, 09:38:41 pm »

This is a program that I wrote that will allow you to analyze the performance of the following sorting algorithms by providing the sort times of each sorting algorithm. 
  • Bubble sort
  • Insertion sort
  • Merge sort
  • Selection sort
  • Quicksort
  • Heapsort
  • Shellsort
This program only supports integers.
The sort times (and step counts) will be outputted into a text and/or excel file.
You may also provide a text file or .csv file (excel file) with numbers to be sorted.
For more information read the Readme.txt file in the download.



Quote from: From Updates.txt
---------------------------------------------------------------------------
- Version 1.0.4
---------------------------------------------------------------------------

- Fixed crash on the cancel sorting progress

---------------------------------------------------------------------------
- Version 1.0.3
---------------------------------------------------------------------------

- Increased the up-down counter's maximum values
Range -> Max: 1073741823
      -> Min: 1073741823
OneList -> Size   : 50,000,000
Multi -> firstList: 10,000,000
      -> lastList : 50,000,000
      -> increment: 10,000,000

- Fixed incorrect value of the first generated stepcount

- Fixed memory leaks

- Other minor fixes

- Add Shellsort algorithm

---------------------------------------------------------------------------
- Version 1.0.2
---------------------------------------------------------------------------

- Fixed random elements swapped methods. List size of 1 and 2 now work
correctly.


Version: 1.0.4 (written in C++)
Download
Download(with Source Code)
« Last Edit: August 31, 2013, 09:39:03 pm by lavakill »
Logged

Quote from: IRC
<EvilWhiteDragon>   what irritates you then lavakill ?
<lavakill>   you
<StealthEye>   knew it :D
*   EvilWhiteDragon smacks lavakill

Trace

  • Honorary Ex-Staff
  • Havoc
  • *****
  • Offline
  • Posts: 346
Re: Algorithm Analysis
« Reply #1 on: August 19, 2013, 05:09:54 pm »

Nice, in C++ I see. Any reason why you wrote it? For a school project?
I did read some stuff about C++ a while back but I didnt have enough time and also lacked inspiration for something to program with it :p
Logged
[23:58:41] <~EvilWhiteDragon> I want to go to town and get drunk
[23:58:53] <~EvilWhiteDragon> why wont any of my friends answer my sms
[23:59:15] <Trace> cuz u dont have any friends?
[00:02:12] * You were kicked from #BI-Moderators by EvilWhiteDragon (FU)

lavakill

  • RenX Game Leader
  • Staff
  • Medium Tank driver
  • ******
  • Offline
  • Posts: 533
Re: Algorithm Analysis
« Reply #2 on: August 19, 2013, 09:35:41 pm »

Originally it was written for a school project, however it was just a win32 console application, so no GUI, just a console window.  Also it was just for bubble, insertion, and merge sort.  Then months after I decided to add more to it (actually rewrite all of it as the original code was messy) and add a GUI just for the fun of it, as it was something to do.
Logged

Quote from: IRC
<EvilWhiteDragon>   what irritates you then lavakill ?
<lavakill>   you
<StealthEye>   knew it :D
*   EvilWhiteDragon smacks lavakill

dhdc

  • Honorary Ex-Member
  • Havoc
  • ****
  • Offline
  • Posts: 325
Re: Algorithm Analysis
« Reply #3 on: August 21, 2013, 08:44:38 pm »

Have you ever seen these YouTube Videos? They were posted on r/programming/ a couple of weeks back. They were posted with the title "Sounds of Sorting" :)

Logged
Gaming Events attended: (iseries) -I37, I40, I42, I43, I45, I46, I47, I48 and I49
Steam: dhdcste

lavakill

  • RenX Game Leader
  • Staff
  • Medium Tank driver
  • ******
  • Offline
  • Posts: 533
Re: Algorithm Analysis
« Reply #4 on: August 23, 2013, 09:25:25 pm »

I've updated the program.

Quote from: From Readme.txt
---------------------------------------------------------------------------
- Version 1.0.1
---------------------------------------------------------------------------

- User file is now correctly checked

- Fixed 'Program Not Responding'
- Added a progress bar
- Added the function to cancel the sorting progress

- Fixed the ascending/descending methods

And also, shame on you guys for not testing my program out and letting me know that the ascending/descending methods were not working :P.
Logged

Quote from: IRC
<EvilWhiteDragon>   what irritates you then lavakill ?
<lavakill>   you
<StealthEye>   knew it :D
*   EvilWhiteDragon smacks lavakill

StealthEye

  • Founder
  • Staff
  • Medium Tank driver
  • ******
  • Offline
  • Posts: 939
Re: Algorithm Analysis
« Reply #5 on: August 23, 2013, 11:17:32 pm »

Weekly updates! Nice release cycle! :)

I still intend to have a look at your code (and add radix sort if I get to it :P), I just didn't find the time yet.
Logged

lavakill

  • RenX Game Leader
  • Staff
  • Medium Tank driver
  • ******
  • Offline
  • Posts: 533
Re: Algorithm Analysis
« Reply #6 on: August 25, 2013, 12:06:29 am »

Great and if you have more time, other sorting algorithms, or just minor performance enhancements to the one's I already have would be awesome.

And also here's a minor fix.

Quote from: Readme.txt
---------------------------------------------------------------------------
- Version 1.0.2
---------------------------------------------------------------------------

- Fixed random elements swapped methods. List size of 1 and 2 now work
correctly.
Logged

Quote from: IRC
<EvilWhiteDragon>   what irritates you then lavakill ?
<lavakill>   you
<StealthEye>   knew it :D
*   EvilWhiteDragon smacks lavakill

dhdc

  • Honorary Ex-Member
  • Havoc
  • ****
  • Offline
  • Posts: 325
Re: Algorithm Analysis
« Reply #7 on: August 25, 2013, 02:59:31 pm »

What about bogo sort?

And the solution is from a newer version of vis studio so i can't open it:*(
« Last Edit: August 25, 2013, 03:15:36 pm by dhdc »
Logged
Gaming Events attended: (iseries) -I37, I40, I42, I43, I45, I46, I47, I48 and I49
Steam: dhdcste

lavakill

  • RenX Game Leader
  • Staff
  • Medium Tank driver
  • ******
  • Offline
  • Posts: 533
Re: Algorithm Analysis
« Reply #8 on: August 25, 2013, 07:52:25 pm »

No bogo sort ... just no.
Logged

Quote from: IRC
<EvilWhiteDragon>   what irritates you then lavakill ?
<lavakill>   you
<StealthEye>   knew it :D
*   EvilWhiteDragon smacks lavakill

StealthEye

  • Founder
  • Staff
  • Medium Tank driver
  • ******
  • Offline
  • Posts: 939
Re: Algorithm Analysis
« Reply #9 on: August 25, 2013, 10:28:54 pm »

Try this (it's not bogosort)

1. Generate a new array with random contents of the same length as the input array.
2. Check if the array is sorted.
3. Check if the generated array contains the same items.
4. Otherwise, try again.

More useful algorithms: http://stackoverflow.com/questions/2609857/are-there-any-worse-sorting-algorithms-than-bogosort-a-k-a-monkey-sort
Logged

lavakill

  • RenX Game Leader
  • Staff
  • Medium Tank driver
  • ******
  • Offline
  • Posts: 533
Re: Algorithm Analysis
« Reply #10 on: August 25, 2013, 10:46:00 pm »

I'm not going to add anything that has the worse case as being unbounded ::).

Nice link Seye ;D.
Logged

Quote from: IRC
<EvilWhiteDragon>   what irritates you then lavakill ?
<lavakill>   you
<StealthEye>   knew it :D
*   EvilWhiteDragon smacks lavakill

StealthEye

  • Founder
  • Staff
  • Medium Tank driver
  • ******
  • Offline
  • Posts: 939
Re: Algorithm Analysis
« Reply #11 on: August 26, 2013, 05:33:35 am »

Oh, in that case, just generate all permutations, and find the sorted one! Only exponential, not unbounded. :)
Logged

lavakill

  • RenX Game Leader
  • Staff
  • Medium Tank driver
  • ******
  • Offline
  • Posts: 533
Re: Algorithm Analysis
« Reply #12 on: August 30, 2013, 09:17:27 pm »

Updated again...

Quote from: Updates.txt
---------------------------------------------------------------------------
- Version 1.0.3
---------------------------------------------------------------------------

- Increased the up-down counter's maximum values
Range -> Max: 1073741823
          -> Min: 1073741823
OneList -> Size   : 50,000,000
Multi -> firstList: 10,000,000
        -> lastList : 50,000,000
        -> increment: 10,000,000

- Fixed incorrect value of the first generated stepcount

- Fixed memory leaks

- Other minor fixes

- Add Shellsort algorithm


If someone has free time on their hands then it would be helpful if you implement these for me:
- radix sort
- bucket sort
- library sort
- patience sort
- smooth sort

Eventually I'll implement these, but it'll take quite a while.
« Last Edit: August 30, 2013, 09:54:37 pm by lavakill »
Logged

Quote from: IRC
<EvilWhiteDragon>   what irritates you then lavakill ?
<lavakill>   you
<StealthEye>   knew it :D
*   EvilWhiteDragon smacks lavakill

StealthEye

  • Founder
  • Staff
  • Medium Tank driver
  • ******
  • Offline
  • Posts: 939
Re: Algorithm Analysis
« Reply #13 on: August 30, 2013, 11:54:07 pm »

One variant of radix sort (tested, albeit not thoroughly):
Code: [Select]
void SortingAlgorithms::RadixSort(int list[], unsigned int sizeOfList)
{
const int maxShift = sizeof(int)*8; // normally 32 or 64 bits
const int bucketBits = 4; // best be a divisor of maxShift
const int bucketCount = 1 << bucketBits; // must be a power of two

int* input = list;
int* output = new int[sizeOfList];

// Sort, starting with least significant bits.
for (int shift = 0; shift < maxShift; shift += bucketBits)
{
int bucket[bucketCount] = {0};

// Count items per bucket.
for (int i = 0; i < sizeOfList; ++i)
{
++bucket[(input[i] >> shift) & (bucketCount - 1)];
}
// Determine offset to end of bucket (exclusive).
for (int i = 1; i < bucketCount; ++i)
{
bucket[i] += bucket[i-1];
}
// Write items (stable sort on the relevant bits).
for (int i = sizeOfList-1; i >= 0; --i)
{
output[--bucket[(input[i] >> shift) & (bucketCount - 1)]] = input[i];
}
// Swap buffers
int* newInput = output; output = input; input = newInput;
}

// Swap buffers back if necessary (iff. ceil(maxShift / bucketBits) is odd)
if (output != list)
{
for (int i = 0; i < sizeOfList; ++i)
{
list[i] = output[i];
}
}
delete output;
}

I believe bucket sort is pretty much the same idea (although it may be mixed with other algos).

Only works for radii that are powers of two (allows some optimizations).
« Last Edit: August 30, 2013, 11:57:24 pm by StealthEye »
Logged

lavakill

  • RenX Game Leader
  • Staff
  • Medium Tank driver
  • ******
  • Offline
  • Posts: 533
Re: Algorithm Analysis
« Reply #14 on: August 31, 2013, 09:38:28 pm »

Great, I'll take a look at that later.

Quote from: Updates.txt
---------------------------------------------------------------------------
- Version 1.0.4
---------------------------------------------------------------------------

- Fixed crash on the cancel sorting progress


I fix the memory the leaks and end up creating a bug.  You win some and you lose some.
Logged

Quote from: IRC
<EvilWhiteDragon>   what irritates you then lavakill ?
<lavakill>   you
<StealthEye>   knew it :D
*   EvilWhiteDragon smacks lavakill
 

April 20, 2024, 02:06:05 am