Monday 25 June 2012

Bubble Sort

Algorithm:
1: start from the beginning of an array
2: compare current and the next element; if current is bigger than the next one, swap them
3: move one place to the right
4: repeat step 2 till you get to the last element (or, more efficiently till you get to the last highest set in its final location; )
5: goto 1

Complexity: O(N^2)
Bubble sort - Wikipedia

No comments:

Post a Comment