Question 21
EasyWhat is the output of this code?
print(sorted('dcba'))
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 the output of this code?
print(sorted('dcba'))
abcd
['a', 'b', 'c', 'd']
['d', 'c', 'b', 'a']
dcba
Sign up free to see the answer and a step-by-step explanation.
What is the result of merging the sorted lists [1, 4, 7] and [2, 3, 9]?
[1, 2, 3, 4, 7, 9]
[9, 7, 4, 3, 2, 1]
[1, 4, 7, 2, 3, 9]
[1, 2, 4, 3, 7, 9]
Sign up free to see the answer and a step-by-step explanation.
After quick sort partitions an array around a pivot, where are the elements smaller than the pivot?
Scattered anywhere
On the pivot's right
At the end of the array
On the pivot's left
Sign up free to see the answer and a step-by-step explanation.
When does bucket sort work best?
When the input is a linked list
When the input is spread fairly evenly over a known range
When the input is very small
When all elements are equal
Sign up free to see the answer and a step-by-step explanation.
What is external sorting?
Sorting only strings
Sorting on another computer
Sorting data that is too large to fit in memory, using disk
Sorting with no comparisons
Sign up free to see the answer and a step-by-step explanation.
In Python, how does list.sort() differ from sorted()?
sorted() works only on numbers
There is no difference
list.sort() sorts the list in place; sorted() returns a new sorted list
list.sort() returns a new list
Sign up free to see the answer and a step-by-step explanation.
Which of these is a divide-and-conquer sorting algorithm?
Merge sort
Selection sort
Bubble sort
Insertion sort
Sign up free to see the answer and a step-by-step explanation.
Which of these sorting algorithms is NOT stable in its usual form?
Insertion sort
Merge sort
Bubble sort
Quick sort
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
a = [5, 1, 4, 2, 8]
n = len(a)
for i in range(n):
for j in range(n - 1 - i):
if a[j] > a[j + 1]:
a[j], a[j + 1] = a[j + 1], a[j]
print(a)
[1, 4, 2, 5, 8]
[8, 5, 4, 2, 1]
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
a = [5, 1, 4, 2, 8]
for j in range(len(a) - 1):
if a[j] > a[j + 1]:
a[j], a[j + 1] = a[j + 1], a[j]
print(a)
[1, 2, 4, 5, 8]
[1, 4, 2, 5, 8]
Sign up free to see the answer and a step-by-step explanation.
[1, 2, 4, 5, 8]
[5, 1, 4, 2, 8]
[1, 4, 5, 2, 8]
[5, 1, 4, 2, 8]