/** |
Showing posts with label bubble sort. Show all posts
Showing posts with label bubble sort. Show all posts
Wednesday, September 19, 2012
Yet another bubble sort comparison
Bubble sort isn't a very efficient algorithm, with O(n2) average and worse-case performance. Anyway, here are some of the algorithm's original and optimized implementations in Java that I've googled up. This computer club blog has a nice impl in java, python, and c++. The Algorithmist wiki, which appears to be a nice and concise resource for prep work, also has a couple of optimizations.
Tuesday, September 18, 2012
Final != Immutable
Just learned that in Java 1.6 (or anything after 1.3, from what I recall from the blog that I read), the final modifier on a primitive int array does not imply immutability (non-modifiable); found this when playing with a couple of sorting algorithms. In the code below, if we want to use the same static array 'array' to be printed before sending it to various successive sorting methods, then we should send clones of it:
-->
public class InsertionSort {
|
Labels:
bubble sort,
final modifier,
immutable,
insertion sort,
java
Subscribe to:
Posts (Atom)