Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 3

Al-Balqa Applied University

‫جامعة البلقاء التطبيقية‬

Prof. Oqeili Saleh Lectures

Prince Abdullah bin Ghazi Faculty


Of Communication and Information Technology
Department of Computer Science

Sorting Methods
Bubble Sort
Bubble sort (sinking sort.)
Bubble sort is a simple sorting algorithm which compares the adjacent
elements in an array and swaps them if they are in the wrong order.
#Python Program for Bubble Sort
arr=[7,5,9,3,6,2,1] Output:
Sorted Array : [1, 2, 3, 5, 6,7,9]
n=len(arr)
for i in range(n):
for j in range(0, n-i-1): O( )

if arr[j] > arr[j+1]:


temp = arr[j+1]
arr[j+1] = arr[j]
arr[j] = temp
print("Sorted Array : ", arr )

You might also like