186 views

2 Answers

0 0 votes

In bubble sort, adjacent elements are compared and swapped if they are in the wrong order. After the first pass, the largest element reaches the last position.

Initial array:

$\texttt{[5, 99, 1, 36, 4, 2]}$

Step-by-step first pass:

Compare $5$ and $99  \rightarrow$ no swap $\rightarrow \texttt{[5, 99, 1, 36, 4, 2]}$
Compare $99$ and $1  \rightarrow$ swap $\rightarrow \texttt{[5, 1, 99, 36, 4, 2]}$
Compare $99$ and $36 \rightarrow$ swap $\rightarrow \texttt{[5, 1, 36, 99, 4, 2]}$
Compare $99$ and $4  \rightarrow$ swap $\rightarrow \texttt{[5, 1, 36, 4, 99, 2]}$
Compare $99$ and $2  \rightarrow$ swap $\rightarrow \texttt{[5, 1, 36, 4, 2, 99]}$

Therefore, after the first pass, the array becomes:

$\texttt{[5, 1, 36, 4, 2, 99]}$

Hence, the correct option is D.

Answer:
Position:
Show:

Related questions

0 0 votes
2 2 answers
133
133 views
GO Classes asked Jul 4
133 views
What is the order of growth of $\texttt{foo}$ in terms of $\texttt{n}$, where $\texttt{n}$ is the length of $\texttt{lst}$?Assume that slicing a list and calling $\texttt...
1 1 vote
2 2 answers
121
121 views
GO Classes asked Jul 4
121 views
Select all sorting algorithms that run in worst-case cost $\text{Θ(n log n)}$.HeapSortInsertionSortMergeSortQuickSort
2 2 votes
2 2 answers
124
124 views
GO Classes asked Jul 4
124 views
Selection sort works in a series of passes over an array. Choose the answer that shows how this array will appear after the first two passes of selection sort.Original ar...
1 1 vote
2 2 answers
118
118 views
GO Classes asked Jul 4
118 views
How many comparisons will binary search be expected to perform to find one member of a list of $1000$ sorted numbers?$999$Approximately $20$Approximately $30$Approximatel...