0% found this document useful (0 votes)
28 views6 pages

Bubble Sort

Bubble sort is a simple sorting algorithm that works by repeatedly stepping through a list of items and comparing adjacent pairs, swapping them if in the wrong order. This pass is repeated until no swaps are needed, indicating the list is sorted. It works by setting a pointer at the start of the list, comparing adjacent items and swapping any out of order pairs. The pointer moves through the list on each pass until it reaches the end. Bubble sort has a worst-case time complexity of O(n^2) but can be O(n) in best case if the list is already sorted.

Uploaded by

Vikas Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views6 pages

Bubble Sort

Bubble sort is a simple sorting algorithm that works by repeatedly stepping through a list of items and comparing adjacent pairs, swapping them if in the wrong order. This pass is repeated until no swaps are needed, indicating the list is sorted. It works by setting a pointer at the start of the list, comparing adjacent items and swapping any out of order pairs. The pointer moves through the list on each pass until it reaches the end. Bubble sort has a worst-case time complexity of O(n^2) but can be O(n) in best case if the list is already sorted.

Uploaded by

Vikas Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 6

Bubble sort

BY AMBRISH GANGAL

WHAT IS IT ??
Bubble sort, also known as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.

HOW IT WORKS ??
DATA is an array with N elements 1. Repeat steps 2 and 3 for K = 1 to N-1 2. Set PTR=1[initializes pass pointer PTR] 3. Repeat while PTR<= N-K[Executes Pass] a) if DATA[PTR]>DATA[PTR+1]then interchange DATA [PTR] and DATA [PTR+1] [End of if structure] b) Set PTR=PTR+1. [End of inner loop] 4. Exit

COMPLEXITY OF BUBBLE SORT


Worst case performance ---- O(n2) Best case performance ---- O(n)

Average case performance ---O(n2)

EXAMPLE :

END OF BUBBLE

You might also like