Saturday, January 11, 2025

Bubble Sort with Python

 Bubble Sort is an elementary sorting algorithm, which works by repeatedly exchanging adjacent elements, if necessary. When no exchanges are required, the file is sorted.

We assume list is an array of n elements. We further assume that swap function swaps the values of the given array elements.

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.

Here is an example on python code below:


``` 

def bubble_sort(arr):

    n = len(arr)

    for i in range(n):

        for j in range(0,n-i-1):

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

                arr[j],arr[j+1] = arr[j+1],arr[j]

    return arr

arr=[64,52,45,85,41,78,96,120,96,125,111,10,11]

print("Original Array: ",arr)

sorted_arr = bubble_sort(arr)

print("Sorted Array: ",sorted_arr)

```


কবীরা গুনাহ কী?

আল্লাহর কিতাব, রাসূলের (সা) সুন্নাহ ও অতীতের পুণ্যবান মনীষীদের বর্ণনা থেকে যেসব জিনিস আল্লাহ ও রাসূল কর্তৃক সুস্পষ্টভাবে নিষিদ্ধ বলে জানা যা...