What would be the state of the following list after each of the first four passes in a Bubble sort, sorting into ascending sequence? 65, 34, 28, 68, 52, 21
How many passes will be made through the list used in part (a) using the Bubble sort algorithm in order to sort it?

See Answers (1)

Accepted Answer

The program that can illustrate the information about the passes on Bubble sort will be:def sort(l):#defining the a method sort that takes list value in parameter   for n in range(len(l)-1, 0, -1):#defining a loop that counts list value and performs the swapping       for i in range(n):#defining another loop that counts range of list           if l[i] > l[i + 1]:#defining if block that check list number value               l[i], l[i + 1] = l[i + 1], l[i]#performing the swappingl=[ 65, 34, 28, 68, 52, 21]#defining a list l that holds integer valueprint("Unsorted list: ")#print messageprint(l)#print list valuesort(l)#calling the sort methodprint("Sorted Array: ")#print messageprint(l)#print sorted list valueHow to illustrate the information?Defining the method "sort," which accepts a list value "l" as an input and produces a loop that counts list values and swaps them.Another loop is constructed within the loop that counts the range of the list and employs a conditional statement.In this scenario, an if block is used to check the list number value and do the switching.A list "l" that holds integer values is used outside the function, as is the print method, which calls and prints its value.Learn more about programs on:https://brainly.com/question/26642771#SPJ1

Related Question in Computers and Technology