Question 51
MediumWhich of these is NOT an in-place sorting algorithm (in its usual array form)?
- 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 of these is NOT an in-place sorting algorithm (in its usual array form)?
Insertion sort
Quick sort
Heap sort
Merge sort
Sign up free to see the answer and a step-by-step explanation.
What is an inversion in an array?
A pair (i, j) with i < j but a[i] > a[j]
An element equal to its index
A duplicate value
A negative number
Sign up free to see the answer and a step-by-step explanation.
Which sort does Shell sort generalise?
Counting sort
Merge sort
Selection sort
Insertion sort, by comparing elements far apart first
Sign up free to see the answer and a step-by-step explanation.
How many passes does bucket sort need when n uniformly distributed numbers are spread into n buckets?
log n passes
One distribution pass, then small sorts inside buckets, O(n) expected
n² passes
n passes
Sign up free to see the answer and a step-by-step explanation.
What is the lower bound on the number of comparisons for any comparison-based sorting algorithm in the worst case?
Ω(n log n)
Ω(log n)
Ω(n²)
Ω(n)
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
a = [6, 2, 5, 1, 3]
pivot = a[-1]
i = 0
for j in range(len(a) - 1):
if a[j] < pivot:
a[i], a[j] = a[j], a[i]
i += 1
a[i], a[-1] = a[-1], a[i]
print(a)
[1, 2, 3, 5, 6]
[2, 3, 1, 5, 6]
Sign up free to see the answer and a step-by-step explanation.
When does insertion sort beat merge sort and quick sort in practice?
Only on linked lists
Never
On small or nearly sorted arrays
On very large random arrays
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
a = [3, 1, 2, 5, 4]
swaps = 0
for i in range(len(a)):
for j in range(len(a) - 1 - i):
if a[j] > a[j + 1]:
a[j], a[j + 1] = a[j + 1], a[j]
swaps += 1
print(swaps)
4
5
Sign up free to see the answer and a step-by-step explanation.
Which sorting algorithm does Python's sorted() and Java's sort for objects use?
Bubble sort
Timsort, a stable hybrid of merge sort and insertion sort
Quick sort
Heap sort
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of radix sort for n numbers of d digits in base b?
O(n²)
O(d log n)
O(n log n)
O(d × (n + b))
Sign up free to see the answer and a step-by-step explanation.
[2, 1, 3, 6, 5]
[3, 2, 1, 6, 5]
3
2