d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Insert Sort Not Working For Large Arrays > Topic
Prev12
Add Reply New Topic New Poll
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Oct 1 2014 11:23pm
Quote (Minkomonster @ Oct 2 2014 01:17am)
This is exactly what I am talking about. You can do run-time analysis without scaring your students into thinking they did something wrong by requiring that their sorting algorithm "work" with an astronomically high set of data. You can teach the same concept with data orders of magnitude lower than that.


Since we are talking about sorts. I have no idea what sort ruby uses for it's default sort() method. It's incredibly fast, so fast that in order to get results in my tests I have to bump up the test data set to 100,000 numbers which it finishes with 0.008 seconds. Radix sort on the same data does 0.0730001. It must be a bucket type of sort implemented in C or something.

edit:: Yep just checked rubys sort is implemented in C located in array.c, although I have no idea what method they use for sorting.

This post was edited by AbDuCt on Oct 1 2014 11:27pm
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Oct 1 2014 11:29pm
Quote (AbDuCt @ Oct 2 2014 12:23am)
Since we are talking about sorts. I have no idea what sort ruby uses for it's default sort() method. It's incredibly fast, so fast that in order to get results in my tests I have to bump up the test data set to 100,000 numbers which it finishes with 0.008 seconds. Radix sort on the same data does 0.0730001. It must be a bucket type of sort implemented in C or something.

edit:: Yep just checked rubys sort is implemented in C located in array.c, although I have no idea what method they use for sorting.


It's a natively implemented quicksort with heavy optimizations.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Oct 1 2014 11:30pm
Quote (Minkomonster @ Oct 2 2014 01:29am)
It's a natively implemented quicksort with heavy optimizations.


Interesting. It makes me all warm and fuzzy inside.
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Oct 1 2014 11:32pm
Quote (AbDuCt @ Oct 2 2014 12:30am)
Interesting. It makes me all warm and fuzzy inside.


I have that effect on people.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 1 2014 11:33pm
Quote (Minkomonster @ Oct 2 2014 01:29am)
It's a natively implemented quicksort with heavy optimizations.


i remember scratching my head when i was looking at java's internal array sort. iirc it used insertion sort for really small arrays. shit got real.
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Oct 1 2014 11:43pm
Quote (carteblanche @ Oct 2 2014 12:33am)
i remember scratching my head when i was looking at java's internal array sort. iirc it used insertion sort for really small arrays. shit got real.


That makes sense. Insertion sort is a stable sort as opposed to quick sort. Less memory required for smaller lists being sorted. Also, since quicksort is a recursively implemented sort it doesn't shine on smaller lists due to the increased overhead. This is true of all divide and conquer sorts. This is where insertion sort will out perform them. You will very often see insertion sort used as the base sort for small or partially sorted lists and then quicksort used for larger sets.
Member
Posts: 2,264
Joined: Jul 7 2007
Gold: 26.00
Oct 2 2014 07:27am
Quote (Minkomonster @ Oct 2 2014 01:02am)
You can do that simply by plugging in the array size to N^2 of O(N^2). You don't tell a bunch of freshmen that your implementation must work for 10^7 sized array. Because before you talk about run-time analysis of comparison based sorting algorithms, all they will think is "shit I ran the program and it froze...I must have messed up the implementation." So you end up having issues like what OP is having. His algorithm is a fine insertion sort, but he is too hung up on making it work for 10^7 because he hasn't been taught anything about the run-time of O(n^2) algorithms. This was a shitty assignment.

The correct way to do this would be to have him implement insertion sort and then give him sample test data. Then have him implement bubble sort, selection sort. Then have him implement mergesort or quicksort. Then after you have gone through all of those tell him to run each with new sample data. This time the data has the 10^7 array. Now he gets to see each sorting algorithm handle that data. After he does that he is to answer one question: Explain why quicksort and mergesort were able to sort this data but insertion and selection sort took ages. By then, in lecture, the professor would have already gone over each algorithm and explained its run-time and what it means. Now the student is equipped to handle this concept.

Do you see the difference?


The two questions before this one was actually bubbleSort and selectionSort! And I had to display the number of swaps each did and the time to sort for different 10^N sized arrays. The name of the class is actually data structures and algorithms so I am just beginning to learn about big O notation and the different times for these sorting algorithms. The 10^7 was a typo on his assignment sheet and i never bothered to go check if there was a revised version of the assignment but surely enough there was lol. We only learned simple sorts at the moment and haven't learned any more complex sorting algorithms but I think they come later in the course! BUT yes you are so right with me freaking out. I just kept wondering why my code wasn't working I thought it was something wrong with my code and just kept wondering why it worked for smaller arrays, and since I was so hung up on that I never bothered to think about just how big the array was.
Go Back To Programming & Development Topic List
Prev12
Add Reply New Topic New Poll