Question 11
EasyWhat is [5, 1, 4, 2, 8] after the first pass of bubble sort (ascending)?
- 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
What is [5, 1, 4, 2, 8] after the first pass of bubble sort (ascending)?
[1, 5, 4, 2, 8]
[1, 4, 2, 5, 8]
[1, 2, 4, 5, 8]
[5, 4, 2, 1, 8]
Sign up free to see the answer and a step-by-step explanation.
What is [64, 25, 12, 22, 11] after the first pass of selection sort (ascending)?
[12, 25, 64, 22, 11]
[25, 12, 22, 11, 64]
[11, 12, 22, 25, 64]
[11, 25, 12, 22, 64]
Sign up free to see the answer and a step-by-step explanation.
Insertion sort is applied to [3, 1, 2]. What does the array look like after the second element has been inserted?
[3, 1, 2]
[2, 1, 3]
[1, 2, 3]
[1, 3, 2]
Sign up free to see the answer and a step-by-step explanation.
What is an in-place sorting algorithm?
One that never swaps elements
One that sorts on disk
One that needs only a small, constant amount of extra memory
One that keeps equal elements in order
Sign up free to see the answer and a step-by-step explanation.
Which of these sorting algorithms is NOT in place in its standard array version?
Insertion sort
Selection sort
Merge sort
Bubble sort
Sign up free to see the answer and a step-by-step explanation.
What is the average-case time complexity of quick sort?
O(log n)
O(n²)
O(n)
O(n log n)
Sign up free to see the answer and a step-by-step explanation.
With a flag that stops when a pass makes no swaps, what is bubble sort's best-case time complexity?
O(n)
O(n log n)
O(n²)
O(log n)
Sign up free to see the answer and a step-by-step explanation.
At most how many passes does bubble sort need for n elements?
n
log n
n − 1
n²
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
print(sorted([3, 1, 2], reverse=True))
[1, 2, 3]
[3, 2, 1]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
print(sorted(['banana', 'apple', 'cherry'], key=len))
['apple', 'banana', 'cherry']
['apple', 'cherry', 'banana']
Sign up free to see the answer and a step-by-step explanation.
[2, 1, 3]
[3, 1, 2]
['cherry', 'banana', 'apple']
['banana', 'cherry', 'apple']