No student devices needed. Know more
5 questions
Which of the following statements is true about Bubble sort?
It works in a random order, swapping elements haphazardly.
It works by repeatedly swapping the adjacent elements if they are in the wrong order.
It compares adjacent elements to check whether they are in the wrong order.
It involves a repetitive iteration.
Bubble sort involves the use of a ________ "for" loop.
random
sequential
nested
serial
Which of the following statements is true about Bubble sorting an array?
It requires several passes to reorder elements of an array.
It is the only method used for sorting arrays.
It involves comparison and swapping of elements.
Elements must be swapped regardless of order.
What is the output of the following piece of code (assume that the code is indented properly):
num = arr.array('i', [12, 3, 2, 6, 1])
for i in range(len(num)):
for j in range(0, len(num)-i-1):
if num[j] > num[j+1] :
num[j], num[j+1] = num[j+1], num[j]
12, 3, 2, 6, 1
12, 6, 3, 2, 1
1, 2, 3, 6, 12
returns an error
The given array is num = arr.array('i', [1, 2, 4, 3]). Bubble sort is used to sort the array elements. How many iterations will be done to sort the array with improvised version?
Explore all questions with a free account