152 views
2 2 votes

After the first complete pass of Bubble Sort on an array of size $n$, which element is guaranteed to be in its correct position?

  1. The smallest element
     
  2. The largest element
     
  3. A randomly chosen element
     
  4. The middle element

2 Answers

1 1 vote

Bubble Sort compares adjacent elements from left to right.

Whenever:

$A[j]>A[j+1]$

the two elements are swapped.

As a result, the larger element keeps moving toward the right.

For example:

$[5,2,4,1,3]$

During the first pass:

$[5,2,4,1,3]$

$\rightarrow [2,5,4,1,3]$

$\rightarrow [2,4,5,1,3]$

$\rightarrow [2,4,1,5,3]$

$\rightarrow [2,4,1,3,5]$

The largest element $5$ reaches the last position.

Therefore, after one complete pass, the largest element is guaranteed to be in its final sorted position.

Answer : B

Answer:
Position:
Show:

Related questions

2 2 votes
2 2 answers
195
195 views
GO Classes asked Aug 12
195 views
Which algorithm-design strategies can reasonably describe Bubble Sort?Greedy Brute force Decrease-and-conquer Divide-and-conquer Dynamic programming
3 3 votes
2 2 answers
226
226 views
GO Classes asked Aug 12
226 views
You are given an initial array:$[22,10,14,37,14,4,3]$For the following array, indicate which sorting algorithm could produce this state after an iteration has completed:$...
3 3 votes
2 2 answers
166
166 views
GO Classes asked Aug 12
166 views
What effect does the initial ordering of the records have on the number of comparisons performed by standard Selection Sort?No effect Only a constant-factor difference Th...
2 2 votes
2 2 answers
186
186 views
GO Classes asked Aug 12
186 views
Suppose Binary Search is used in Insertion Sort to locate where the $i$th element should be inserted among the first $i-1$ elements.What is the worst-case running time of...