Question 41
MediumWhich sort makes the minimum number of swaps (at most n − 1)?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
Which sort makes the minimum number of swaps (at most n − 1)?
Selection sort
Insertion sort
Quick sort
Bubble sort
Sign up free to see the answer and a step-by-step explanation.
Quick sort always picks the last element as pivot. Which input gives the worst case?
A random array
An already sorted array
An array of distinct random numbers
An array with one element
Sign up free to see the answer and a step-by-step explanation.
Which sort is best for an array that is almost sorted, with a few elements out of place?
Selection sort
Quick sort with the first element as pivot
Heap sort
Insertion sort
Sign up free to see the answer and a step-by-step explanation.
Which sorting algorithms are stable? (Select all that apply.)
Merge sort
Insertion sort
Heap sort
Quick sort (usual in-place form)
Sign up free to see the answer and a step-by-step explanation.
Which sort is commonly used for very large data that doesn't fit in memory?
Selection sort
External merge sort
Bubble sort
Counting sort with huge ranges
Sign up free to see the answer and a step-by-step explanation.
Radix sort is used on 1,000 six-digit numbers with counting sort per digit. How many passes does it make?
1,000
10
6
3
Sign up free to see the answer and a step-by-step explanation.
Why must radix sort use a stable sort for each digit?
So that the order from earlier (less significant) digits is kept for equal digits
To sort negative numbers
It doesn't need to
To save memory
Sign up free to see the answer and a step-by-step explanation.
What is the best-case time of bubble sort with an early-exit flag?
O(1)
O(n log n)
O(n²)
O(n)
Sign up free to see the answer and a step-by-step explanation.
What does heap sort do first?
Merges pairs of elements
Sorts the first half
Builds a max-heap from the array
Picks a random pivot
Sign up free to see the answer and a step-by-step explanation.
Which algorithm sorts n integers in the range 0 to k in O(n + k)?
Merge sort
Heap sort
Counting sort
Shell sort
Sign up free to see the answer and a step-by-step explanation.