Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
823 views
in Computer by (55 points)
Define a function BSORT(ARR) in Python, which accepts a list ARR of numbers as an argument. The function Is supposed to sort the list ARR in ascending order using Bubble Sort Technique.

Please log in or register to answer this question.

1 Answer

0 votes
by (35 points)
Here's a Python implementation of the Bubble Sort Technique for sorting a list of numbers in ascending order:

def BSORT(arr):

    n = len(arr)

    # Traverse through all array elements

    for i in range(n):

        # Last i elements are already sorted

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

            # Traverse the array from 0 to n-i-1

            # Swap if the element found is greater

            # than the next element

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

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

    return arr

In this implementation, we have used two nested loops to traverse the array and compare adjacent elements. In each pass, we compare each pair of adjacent elements and swap them if they are not in the correct order. By the end of each pass, the largest element will have "bubbled" up to the end of the array. We repeat this process until the entire array is sorted.

To use this function, you can simply call it and pass in your list of numbers as an argument. For example:

arr = [64, 34, 25, 12, 22, 11, 90]

sorted_arr = BSORT(arr)

print(sorted_arr)

This will output: [11, 12, 22, 25, 34, 64, 90], which is the sorted version of the input list.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...