0% found this document useful (0 votes)
6 views3 pages

Bubble Sort

Bubble Sort is a simple sorting algorithm that sorts a list by repeatedly swapping adjacent elements if they are in the wrong order. The process involves comparing elements, swapping them if necessary, and repeating until the entire list is sorted. The provided pseudocode outlines the algorithm's steps for implementation.

Uploaded by

money2005qw
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Bubble Sort

Bubble Sort is a simple sorting algorithm that sorts a list by repeatedly swapping adjacent elements if they are in the wrong order. The process involves comparing elements, swapping them if necessary, and repeating until the entire list is sorted. The provided pseudocode outlines the algorithm's steps for implementation.

Uploaded by

money2005qw
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Bubble Sort

Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the
adjacent elements if they are in the wrong order.

Working

1.​ Start from the first element and compare it with the next.
2.​ If the first element is greater than the second, swap them.
3.​ Move to the next pair and repeat the process for the entire list.
4.​ Repeat the process for multiple passes until the list is sorted.
Step 1 − Check if the first element in the input array is greater than the next element in the
array.

Step 2 − If it is greater, swap the two elements; otherwise move the pointer forward in the array.

Step 3 − Repeat Step 2 until we reach the end of the array.

Step 4 − Check if the elements are sorted; if not, repeat the same process (Step 1 to Step 3)
from the last element of the array to the first.

Step 5 − The final output achieved is the sorted array.

Pseudocode
Algorithm: Sequential-Bubble-Sort (A)

fori ← 1 to length [A] do

for j ← length [A] down-to i +1 do

if A[A] < A[j-1] then

Exchange A[j] ⟷ A[j-1]

You might also like