Question 1: Correct Incorrect
Question 1: Correct Incorrect
Question 1: Correct Incorrect
Question 1
0.0/1.0 point (ungraded)
Select all the sorting algorithms which are stable and asymptotically optimal.
Quicksort
Insertion sort
Mergesort correct
incorrect
Let me explain:
Quicksort is asymptotically optimal on average, but it is not stable. Insertion sort is
stable, but it is not optimal, as it has O(N2) running time. In this list, only Mergesort is
both stable and asymptotically optimal.
Question 2
Bookmark this page
Question 2
1.0/1.0 point (ungraded)
Consider the Radix sort algorithm which uses Bucket sort inside to sort by certain
digits. The following array is being sorted: [135, 187, 236, 105, 157, 206]. Select the
intermediate state of this array after the first stage of Radix sort, i.e. after running
Bucket sort for the first time.
Question 3
Bookmark this page
Question 3
1.0/1.0 point (ungraded)
Which of the listed sorts from the C/C++ standard libraries is generally the fastest
one?
std::stable_sort
std::sort correct
qsort
Let me explain:
In qsort, the comparator is never inlined, so it is slower than C++ sorts. So the right
answer is std::sort, which is generally faster than std::stable_sort
Question 4
Bookmark this page
Question 4
1.0/1.0 point (ungraded)
Assume that we search where q = 6 is in a sorted array using binary search. Which
sequence of elements x which are compared to q may appear during the search?
9, 10, 4, 5, 6
11, 5, 3, 7, 6
10, 2, 7, 4, 6 correct
12, 8, 9, 3, 6
Let me explain:
In all the other cases the sequence can not appear during the binary search. For
example, in the first case 10 can not appear after 9, because 9 is greater than q = 6,
so the search will be continued among the numbers which are not greater than 9.
Question 5
Bookmark this page
Question 11
0.0/1.0 point (ungraded)
Assume that it is needed to find where to insert an element into a sorted array of
integers. Which tools from standard libraries may be useful?