Recent questions tagged sorting

1 1 vote
1 1 answer
135
135 views
Let $P$ be the problem of sorting $n\geq1$ elements using only comparisons.Consider the class of all comparison-based algorithms that correctly solve $P$.What is the asym...
3 3 votes
2 2 answers
240
240 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:$...
2 2 votes
2 2 answers
215
215 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
180
180 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
210
210 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...
2 2 votes
2 2 answers
171
171 views
After the first complete pass of Bubble Sort on an array of size $n$, which element is guaranteed to be in its correct position?The smallest element The largest element A...
2 2 votes
2 2 answers
183
183 views
Problem: Sort a file of huge records with tiny keys.Example application: Reorganize your MP-$3$ files.Which sorting method to use?a system sort, guaranteed to run in time...
1 1 vote
2 2 answers
157
157 views
When is insertionsort a good choice for sorting an array?Each component of the array requires a large amount of memory. Each component of the array requires a small amoun...
1 1 vote
2 2 answers
162
162 views
Suppose that a selectionsort of $100$ items has completed $42$ iterations of the main loop. How many items are now guaranteed to be in their final spot (never to be moved...
1 1 vote
2 2 answers
158
158 views
In a selectionsort of n elements, how many times is the swap function called in the complete execution of the algorithm?$1$ $n-1$ $n\log n$ $n^2$
2 2 votes
2 2 answers
174
174 views
The nontrivial operation involved in the bubble sort is comparing two numbers, i.e., checking the $\texttt{if}$ condition in the inner $\texttt{for}$ loop.How many compar...
2 2 votes
2 2 answers
189
189 views
Consider an array containing $2n$ elements:$1,\ n+1,\ 2,\ n+2,\ 3,\ n+3,\ldots,n,\ 2n$For example, when $n=8$:$1,\ 9,\ 2,\ 10,\ 3,\ 11,\ 4,\ 12,\ 5,\ 13,\ 6,\ 14,\ 7,\ 15...
1 1 vote
1 1 answer
120
120 views
You need to sort hotels on a travel website according to their star rating.Which sorting algorithm would be the most appropriate?Insertion sort Merge sort Quicksort Bucke...
1 1 vote
1 1 answer
166
166 views
Mergesort recursively sorts the two halves of an array.After both recursive calls have finished, but before the merge operation, which statement must be true?The complete...
1 1 vote
1 1 answer
141
141 views
A quadratic sorting algorithm has completed four iterations. The array is now:$1,\ 2,\ 3,\ 4,\ 5,\ 0,\ 6,\ 7,\ 8,\ 9$Assume that selection sort places the largest element...
0 0 votes
1 1 answer
145
145 views
Which of the following algorithms is better when dealing with reverse sorted numbers?Quicksort Heap sort Insertion sort all are equally good
2 2 votes
2 2 answers
181
181 views
Which of the following is correct order of increasing time complexity of algorithmsTower of Hanoi with $n$ disk.Binary search given $n$ sorted numbers.Heap sort given $n$...
2 2 votes
2 2 answers
878
878 views
Consider the problem of sorting the given array in ascending order:\[P=[1,2,3,5,4]\]Consider two sorting algorithms Bubble Sort $\text{(BS)}$ and Insertion Sort $\text{(I...