Sorting
Sorting
SORTING
•Sorting refers to the operation of
arranging data in some given order,
such as increasing or decreasing, with
numerical data or alphabetically, with
character data.
SORTING TECHNIQUES
☞Selection sort.
☞Bubble sot.
☞Insertion Sort.
☞Merge Sort.
☞…..
BUBBLE SORT
Properties
•Stable
•O(1) extra space
•O(n2) comparisons and swaps
•Adaptive: O(n) when nearly sorted
•Bubble sort has many of the same properties as insertion sort, but has slightly
higher overhead. In the case of nearly sorted data, bubble sort takes O(n)
time, but requires at least 2 passes through the data (whereas insertion sort
requires something more like 1 pass).
BUBBLE SORT
44 33 33 33 33
33 44 44 44 44
55 55 55 22 22
22 22 22 55 11
11 11 11 11 55
PHASE 1
33 33 33 33
44 44 22 22
22 22 44 11
11 11 11 44
55 55 55 55
PHASE 2
33 22 22
22 33 11
11 11 33
44 44 44
55 55 55
PHASE 3
22 11
11 22
33 33
44 44
55 55
PHASE 3
Selection Sort