edited by
1,009 views
0 votes
0 votes

Consider the following sorting algorithms:

  1. Bubble sort
  2. Insertion sort
  3. Selection sort


Which ONE among the following choices of sorting algorithms sorts the numbers in the array $[4,3,2,1,5]$ in increasing order after exactly two passes over the array?

  1. $\text{(i)}$ only
  2. $\text{(iii)}$ only
  3. $\text{(i)}$ and $\text{(iii)}$ only
  4. $\text{(ii)}$ and $\text{(iii)}$ only

edited by

1 Answer

0 votes
0 votes
Bubble sort needs 3. Insertion sort wastes 1 to assume first element as sorted. Selection sort does it in 2 with first pass swap [4, 1] and second pass swap [3, 2]. So B.

 
Answer:

Related questions

918
views
1 answers
0 votes
Arjun asked Feb 16
918 views
​​​​Consider performing depth-first search (DFS) on an undirected and unweighted graph $G$ starting at vertex $s$. For any vertex $u$ in $G, d[u]$ is the length o...
1.4k
views
3 answers
0 votes
Arjun asked Feb 16
1,431 views
Consider sorting the following array of integers in ascending order using an inplace Quicksort algorithm that uses the last element as the pivot.\begin{array}{|l|l|l|l|l|...
991
views
1 answers
0 votes
Arjun asked Feb 16
991 views
​​​​​Let $F(n)$ denote the maximum number of comparisons made while searching for an entry in a sorted array of size $n$ using binary search.Which ONE of the fo...
806
views
1 answers
0 votes
Arjun asked Feb 16
806 views
​​​​​​Consider the directed acyclic graph (DAG) below:Which of the following is/are valid vertex orderings that can be obtained from a topological sort of the...