Bubble sort

Post on 15-Jan-2015

2.465 views 1 download

description

Bubble sort

Transcript of Bubble sort

Bubble Sort

Part 1 of 2 - Series

Overview

• Simplest of all sorts• Compare first 2 elements and swap if out of

order, keep doing for each adjacent pair of elements until end of array – last element is largest element in array

• Do procedure for each next largest element until array is sorted.

Pseudocode

Performance

Worst case performance: O(n^2)Best case performance O(n)

Improvements

• Optimized Bubble Sort

• Comb Sort…