Carey Brown wrote:It would be interesting to see some performance numbers for very large arrays comparing your method to a simple bubble sort.
Your method has these nested loops
A bubble sort has these
Note the inner loop gets shorter and shorter as the outer loop progresses.
Junilu Lacar wrote:Instead of writing your own printer() method, you could just use java.util.Arrays.toString() to display an int[]. To display nested arrays, you can use Arrays.deepToString()
Dawid Smith wrote:I didn't know that such methods exist. Still, what do you think about writing your own version just for practice? I imagine it seems supereasy for someone experienced but I had to think how to print those results
Dawid Smith wrote:Still, what do you think about writing your own version just for practice?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Junilu Lacar wrote:If it's your first try, then it's a pretty good try. This algorithm, however, is quite inefficient. If I'm not mistaken, it is best case and worst case O(n²) which means that for large arrays, it takes a very long time, even if it's already sorted. You're basically looking through the entire list NxN times to find the largest unsorted element, including the elements that you've already looked at before and determined to be larger than all others.
Sorting algorithms are a basic area of study in computer science so I suggest you take a look at the various ones already existing and commonly used and compare them with yours to see what kind of improvements you might make.
Winston Gutkowski wrote:
Dawid Smith wrote:Still, what do you think about writing your own version just for practice?
Nothing wrong with it at all; just don't expect too much in the way of enlightenment unless you repeat the process at least 10,000 times, or work with arrays involving millions of objects, which probably isn't very practical.
Winston Gutkowski wrote:I'm with Junilu - right now, you might get more mileage out of looking at sorting algorithms and working out why you might use them; but don't ignore the simple ones simply because they're supposedly "inefficient" (O(n²) or worse).
Dawid Smith wrote:Right now, my studying is heavily skewed towards writing my own stuff instead of looking up what's already out there. Maybe that's a mistake.
Liutauras Vilda wrote:@OP
Very nicely indented and formatted code. Have a cow for disciplined approach on that.
Campbell Ritchie wrote:Once you have passed all your exams and got a job, you will sort your array like this
A $40,000 starting salary?Dawid Smith wrote:. . . But.. where would the fun be in that?
. . .
Campbell Ritchie wrote:
A $40,000 starting salary?Dawid Smith wrote:. . . But.. where would the fun be in that?
. . .
Campbell Ritchie wrote:Once you have passed all your exams and got a job, you will sort your array like this
There are three kinds of actuaries: those who can count, and those who can't.
Carey Brown wrote:A side topic here would be how to benchmark your program. It seems like sorting might be as good a place as any to compare benchmarks from various techniques. I would be interested to know how the streaming version compares to the Arrays.sort version, for instance.
Try here to see what the algorithms look like animated. I can't remember whether they provide details of the algorithm on that site, too, but you can always search Wikipedia or similar.Dawid Smith wrote:. . . some of the well-known algorithms . . .
Mark Ii wrote:There is an optimized bubble sort. More efficient.
Here is the link. webpage
[/code]
Campbell Ritchie wrote:
Try here to see what the algorithms look like animated. I can't remember whether they provide details of the algorithm on that site, too, but you can always search Wikipedia or similar.Dawid Smith wrote:. . . some of the well-known algorithms . . .
Kindly don't simply promote that tutorial, which I presume you have written yourself.The link doesn't actually add anything new.Ashish Chandra Gupta wrote:. . . Sort Array