Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

201.

What is the average case time complexity of cycle sort?(a) O(n^2)(b) O(n log n)(c) O(log n)(d) O(n)I got this question at a job interview.I would like to ask this question from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

The correct option is (a) O(n^2)

The EXPLANATION is: The average case performance of CYCLE SORT is O(n^2). It is because it has to MAKE n comparisons for each element of the ARRAY.

202.

What is the best case time complexity of cycle sort?(a) O(n^2)(b) O(n)(c) O(n log n)(d) O(1)I got this question in an internship interview.My question comes from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

Right answer is (a) O(n^2)

Easy explanation - Best case time complexity of cycle SORT is O(n^2). This shows that cycle sort is not an adaptive sorting algorithm and thus makes it undesirable when the given array is ALREADY almost SORTED.

203.

What is the auxiliary space requirement of cycle sort?(a) O(n)(b) O(1)(c) O(log n)(d) O(n log n)This question was posed to me in examination.This intriguing question comes from Sorting in portion Sorting of Data Structures & Algorithms II

Answer» RIGHT option is (b) O(1)

Easy explanation - CYCLE SORT REQUIRES an auxiliary space of O(1). So this makes it an in-place sorting algorithm.
204.

What is the worst case time complexity of cycle sort?(a) O(n)(b) O(log n)(c) O(n log n)(d) O(n^2)This question was posed to me in my homework.Question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct ANSWER is (d) O(n^2)

For explanation: The WORST case performance of CYCLE sort is O(n^2). It is because it has to make n comparisons for each ELEMENT of the array.

205.

Which of the following is an example of an unstable sorting algorithm?(a) cycle sort(b) insertion sort(c) bubble sort(d) merge sortThis question was addressed to me in quiz.The origin of the question is Sorting in portion Sorting of Data Structures & Algorithms II

Answer» CORRECT choice is (a) cycle sort

Easiest explanation - Out of the given options only cycle sort is an UNSTABLE sorting algorithm. This implies that the RELATIVE position of equal valued ELEMENTS in the input and sorted array does not remain the same when we USE cycle sort.
206.

Which of the following sorting algorithms can be considered as improvement to the binary tree sort?(a) Heap sort(b) Quick sort(c) Selection sort(d) Insertion sortThis question was addressed to me by my college professor while I was bunking the class.The origin of the question is Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (a) Heap SORT

Easiest explanation - Heap sort is basically IMPROVEMENT to the BINARY tree sort. Heap sort builds a heap on the input element by adjusting the position of the ELEMENTS within the original array, rather than creating nodes as in binary tree sort.

207.

Which of the following is false?(a) Binary tree sort and quick sort have same running time(b) Binary tree sort used BST as work area(c) As the number of elements to sort gets larger, binary tree sort gets more and more efficient(d) Both quick sort and binary tree are in place sorting algorithmsThis question was addressed to me in an online quiz.The above asked question is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

Right answer is (d) Both quick sort and BINARY tree are in place SORTING algorithms

To explain: Binary tree sort and quick sort have same running TIME i.e O(nlogn)

in average CASE and O(n^2) in worst case. Binary tree is not in-place sorting ALGORITHM.

208.

Binary tree sort is an in-place sorting algorithm.(a) True(b) FalseThis question was addressed to me in an online interview.This interesting question is from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

The correct option is (b) False

Easy EXPLANATION - In binary tree sort it is required to reserve one tree node for each array ELEMENT. Its implementation requires two pointer VARIABLES for each node. So, it requires extra memory. The worst case space complexity of binary tree sort is Θ(n). THEREFORE, binary tree sort is not an in-place sorting algorithm.

209.

What is the best case time complexity of the binary tree sort?(a) O(n)(b) O(nlogn)(c) O(n^2)(d) O(logn)The question was posed to me in final exam.The query is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer» CORRECT OPTION is (b) O(nlogn)

Easy explanation - The best case OCCURS when the BST is BALANCED. So, when tree is balanced we require O(nlogn) time to build the tree and O(N) time to traverse the tree. So, the best case time complexity of the binary tree sort is O(nlogn).
210.

What is the worst case time complexity of the binary tree sort?(a) O(n)(b) O(nlogn)(c) O(n^2)(d) O(logn)I got this question during a job interview.Question is taken from Sorting in section Sorting of Data Structures & Algorithms II

Answer» CORRECT answer is (c) O(n^2)

EXPLANATION: For the binary tree sort the worst case when the BST constructed is unbalanced. BST gets unbalanced when the ELEMENTS are already sorted. So, in the worst case, O(n^2) time is required to built the BST and O(n) time to traverse the tree. THEREFORE, the worst case time complexity is O(n^2) + O(n) = O(n^2).
211.

In binary tree sort, we first construct the BST and then we perform _______ traversal to get the sorted order.(a) inorder(b) postorder(c) preorder(d) level orderThis question was addressed to me by my college director while I was bunking the class.My query is from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

The CORRECT OPTION is (a) inorder

To explain: In binary tree SORT is a sort ALGORITHM where a binary search tree is built from the elements to be sorted, and then we perform inorder traversal on the BST to GET the elements in sorted order.

212.

Consider the original array 17 8 12 4 26.How many comparisons are needed to construct the BST on the original array?(a) 5(b) 4(c) 7(d) 10This question was addressed to me at a job interview.The above asked question is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (d) 10

Explanation: Original ARRAY is 17 8 12 4 26. The BST built on this array is shown in the figure below.

To built the BST, we travel down the TREE until a leaf is reached. THEREFORE, for every element we compare the element with the internal nodes until we the leaves and then once again compare the element with its parent to decide WHETHER it is right child or left child. So, for given array we need to perform 10 comparisons to build the BST.

213.

Which of the following sorting algorithm uses the method of insertion?(a) cube sort(b) bubble sort(c) quick sort(d) selection sortI had been asked this question in an online quiz.My doubt stems from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer» RIGHT choice is (a) cube sort

For explanation: Cube sort is the only algorithm from the GIVEN ones that uses the method of INSERTION. Other than this, the insertion sort also uses the method of insertion for SORTING.
214.

Cube sort is a comparison based sort.(a) true(b) falseThis question was addressed to me in a national level competition.The doubt is from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

The correct ANSWER is (a) true

The EXPLANATION is: CUBE sort is a comparison based sorting algorithm. This is because it compares elements in ORDER to sort them.

215.

Which of the following is a disadvantage of cube sort?(a) high memory overhead for small data(b) high memory overhead for any data(c) balancing is slow(d) Iteration is slowI have been asked this question in an international level competition.My question comes from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (a) HIGH memory overhead for small DATA

To explain: In a GENERAL CASE the memory overhead of cube sort is low. But when the data set is small then in that case the memory overhead becomes high.

216.

Cube sort is an in place sorting algorithm.(a) true(b) falseThis question was posed to me in exam.This interesting question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (b) false

The explanation is: Cube SORT has an AUXILIARY SPACE complexity of O(n). So it does not qualify to be an in-place sort.

217.

Which of the following algorithm is stable?(a) heap sort(b) cube sort(c) quick sort(d) bogosortI have been asked this question during an interview.The query is from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The CORRECT ANSWER is (d) bogosort

The EXPLANATION is: Out of the GIVEN algorithms only cube sort is stable. This implies that the relative POSITION of equal valued elements in the input and sorted array remains the same.

218.

What is the average case time complexity of cube sort?(a) O(n^2)(b) O(n log n)(c) O(log n)(d) O(n)The question was asked in a national level competition.This question is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Right option is (b) O(N log n)

The BEST EXPLANATION: The average case performance of cube sort is O(n log n). This is the fastest POSSIBLE complexity with a comparison based sort.

219.

What is the best case time complexity of cube sort?(a) O(n^2)(b) O(n)(c) O(n log n)(d) O(1)I have been asked this question in examination.My doubt is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Right option is (b) O(n)

The best I can EXPLAIN: Best case time complexity of CUBE SORT OCCURS when the input ARRAY is almost sorted. So in such a case only O(n) time is required for sorting.

220.

What is the auxiliary space requirement of cube sort?(a) O(n)(b) O(1)(c) O(log n)(d) O(n log n)I have been asked this question in quiz.My question is taken from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer» RIGHT choice is (a) O(n)

The best I can EXPLAIN: CUBE sort REQUIRES an AUXILIARY space of O(n). This is the worst case of auxiliary space complexity.
221.

What is the worst case time complexity of cube sort?(a) O(n)(b) O(log n)(c) O(n log n)(d) O(n2)This question was addressed to me during an online exam.The doubt is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct option is (c) O(n LOG n)

The best EXPLANATION: The WORST case performance of cube sort is O(n log n). This is the FASTEST possible complexity with a comparison based sort.

222.

Which of the following is an example of parallel sorting technique?(a) bogo sort(b) sleep sort(c) cube sort(d) merge sortI have been asked this question in exam.My doubt is from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (c) cube sort

Easy explanation - Out of the GIVEN OPTIONS only cube sort is a parallel sorting algorithm. It builds self balancing MULTI DIMENSIONAL arrays from the INPUT keys.

223.

What is the usual size of a run in tim sort?(a) 32(b) less than 32(c) 32-64 depending on size of the array(d) 64I got this question in an online quiz.This question is from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

Right OPTION is (c) 32-64 DEPENDING on size of the array

Best explanation: Usually the size of the run is chosen somewhere between 32 and 64. The size of run is preferably chosen in powers of 2 in order to MAINTAIN balance while merging the sorted runs.

224.

In which case will tim sort will work as an insertion sort?(a) when no. of elements are less than 64(b) when no. of elements are greater than 64(c) when no. of elements are less than size of run(d) when no. of elements are less than 32I have been asked this question in semester exam.My question comes from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (c) when no. of elements are less than size of run

Easiest explanation - Tim sort uses a hybrid of INSERTION and MERGE sort. It reduces to insertion sort when the size of array is less than the size of run as insertion sort is EFFICIENT in sorting SMALL arrays.

225.

Why is insertion sort preferred over other sorting algorithms (like selection sort, bubble sort etc.) for Tim sort implementation?(a) Because insertion sort is faster and adaptive(b) Because insertion sort requires less space(c) Because insertion sort is easy to implement(d) Because insertion sort is easy to understandThis question was posed to me in an interview.The query is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct option is (a) Because insertion sort is faster and adaptive

The BEST explanation: When SMALL arrays need to be sorted then insertion sort proves to be the best choice. Also, it is adaptive so it PERFORMS BETTER than others when the given array is fully/partially sorted.

226.

Which of the following algorithm is implemented internally in java when we use function arrays.sort()?(a) intro sort(b) quick sort(c) tim sort(d) merge sortThis question was posed to me in exam.I need to ask this question from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

The CORRECT answer is (c) TIM sort

Explanation: JAVA makes use of Tim sort internally for implementing arrays.sort(). It is mainly DUE to the fastness of this algorithm in COMPARISON to other comparison based sorts.

227.

What is the auxiliary space requirement of Tim sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)This question was posed to me by my school principal while I was bunking the class.Query is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (a) O(N)

Best EXPLANATION: TIM SORT is a hybrid of merge sort and insertion sort. It requires to merge SORTED runs which require a third array of the size equal to the sum of the two runs. So in worst case the auxiliary space requirement will be O(n).

228.

What is the average time complexity of Tim sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)I have been asked this question by my college director while I was bunking the class.My enquiry is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer» CORRECT answer is (b) O(n log n)

EXPLANATION: Average time complexity of TIM SORT remains to be O(n log n). It is the same as the average case complexity of merge sort.
229.

What is the worst case time complexity of Tim sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)The question was asked by my college director while I was bunking the class.I'd like to ask this question from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Right choice is (b) O(N log n)

Easy explanation - WORST case TIME complexity of Tim SORT is O(n log n). It is because the worst complexity of merge sort is O(n log n) and INSERTION sort is only applied for small arrays.

230.

What is the best case time complexity of Tim sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)The question was posed to me by my college director while I was bunking the class.My question is taken from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Right OPTION is (a) O(N)

For EXPLANATION: Best case time complexity of Tim sort occurs when the input array is already sorted. In such a case only ONE run will be required.

231.

Tim sort is a comparison based sort.(a) true(b) falseI got this question in an online quiz.Asked question is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Right answer is (a) true

Easy EXPLANATION - Merge SORT and insertion sort are comparison based sorts. Thus OVERALL Tim sort ALSO becomes a comparison based sort.

232.

Which of the following sorting algorithm is not in-place?(a) insertion sort(b) tim sort(c) quick sort(d) intro sortThe question was asked in class test.My question is based upon Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

Right CHOICE is (B) tim sort

Explanation: Tim sort is not an in-place sorting algorithm as it REQUIRES auxiliary space. It is because it requires to merge sorted runs which requires a THIRD array of the SIZE equal to the sum of the two runs.

233.

Which of the following sorting algorithm is stable?(a) Tim sort(b) Introsort(c) Quick sort(d) Heap sortThis question was addressed to me during an internship interview.Origin of the question is Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (a) Tim sort

Easiest explanation - Out of the GIVEN OPTIONS Tim sort is the only ALGORITHM which is stable. As both CONSTITUENTS of Tim sort (I.e insertion sort and merge sort) are stable so Tim sort ALSO becomes stable.

234.

Tim sort begins sorting the given array by using which of the following sorting algorithm?(a) selection sort(b) quick sort(c) insertion sort(d) merge sortI have been asked this question during a job interview.I'm obligated to ask this question of Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

The correct OPTION is (C) insertion sort

To EXPLAIN: Tim sort begins sorting any given ARRAY by using insertion sort for each run. The array is divided into smaller parts for this purpose, each part having a size EQUAL to value of run. Then these small parts called runs are merged in order to obtain sorted array.

235.

Which of the following sorting algorithm is a constituent of tim sort?(a) selection sort(b) quick sort(c) merge sort(d) heap sortI have been asked this question in an interview.My enquiry is from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The correct CHOICE is (c) merge sort

The explanation is: TIM sort is a HYBRID sorting ALGORITHM which means it uses more than one sorting algorithm as a routine. It is DERIVED from insertion sort and merge sort.

236.

Which of the following is Python’s standard sorting algorithm?(a) quick sort(b) introsort(c) merge sort(d) tim sortThe question was posed to me by my college director while I was bunking the class.My doubt stems from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (d) tim sort

The best EXPLANATION: Tim sort has been python’s standard sorting algorithm since its version 2.3. It is an EXAMPLE of hybrid sorting algorithm which means it USES more than ONE sorting algorithm as a routine.

237.

Which of the following sorting algorithm will be preferred when the size of partition is between 16 and 2 log(n) while implementing introsort?(a) quick sort(b) insertion sort(c) heap sort(d) merge sortThe question was asked by my school principal while I was bunking the class.Origin of the question is Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (a) quick sort

Easiest explanation - Quicksort proves to be the best sorting ALGORITHM for mid SIZED arrays as it has low space and time COMPLEXITY. Thus quick sort is preferred when size of PARTITION is between 16 and 2 log(N).

238.

What is the cut-off for switching from quick sort to heap sort in the implementation of introsort?(a) 16(b) n^2(c) n log(n)(d) 2 log (n)I have been asked this question in quiz.My question is taken from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (d) 2 log (n)

Easy EXPLANATION - Quicksort has a worst CASE time complexity of O(n^2) which is not preferable. So in ORDER to avoid worst case of quicksort, INTROSORT switches to heap SORT when the depth is greater than 2 log(n). This particular value has been deduced experimentally.

239.

What is the cut-off for switching from quick sort to insertion sort in the implementation of introsort?(a) 4(b) 8(c) 16(d) 32The question was posed to me in an interview for job.Question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer» RIGHT option is (c) 16

For explanation: When small ARRAYS needs to be sorted then INSERTION sort proves to be the best choice. So when the size of the partition is less than 16 INTROSORT switches to insertion sort. This particular value has been deduced EXPERIMENTALLY.
240.

Why is insertion sort preferred over other sorting algorithms (like selection sort, bubble sort etc.) for introsort implementation?(a) Because insertion sort is faster and adaptive(b) Because insertion sort requires less space(c) Because insertion sort is easy to implement(d) Because insertion sort is easy to understandThis question was posed to me in an online interview.This key question is from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

Right answer is (a) Because insertion SORT is faster and adaptive

BEST explanation: When SMALL arrays NEED to be sorted then insertion sort proves to be the best choice. Also it is adaptive so it PERFORMS better than others when the given array is fully/partially sorted.

241.

Why is heap sort preferred over merge sort for introsort implementation?(a) Because heap sort is faster(b) Because heap sort requires less space(c) Because heap sort is easy to implement(d) Because heap sort is easy to understandI had been asked this question by my college director while I was bunking the class.Query is from Sorting in division Sorting of Data Structures & Algorithms II

Answer» CORRECT answer is (b) Because heap sort REQUIRES less space

Best explanation: Both heap sort and merge sort have the same time complexity. But heap sort is an in-place sorting ALGORITHM whereas merge sort requires O(n) AUXILIARY space which makes heap sort a more preferable option.
242.

What is the auxiliary space requirement of introsort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)This question was addressed to me in final exam.Question is taken from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct CHOICE is (d) O(log N)

For explanation: Introsort is a hybrid of quick SORT, heap sort and INSERTION sort. So like quick sort it may use O(log n) auxiliary space in the stack to store call STATEMENTS.

243.

What is the average time complexity of introsort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)The question was asked in semester exam.The query is from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

Right ANSWER is (b) O(n log n)

Easiest EXPLANATION - Average time complexity of introsort REMAINS to be O(n log n) as for most of the cases QUICK sort and heap sort are used which have O(n log n) time complexity for an average case.

244.

What is the worst case time complexity of introsort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)The question was asked by my college professor while I was bunking the class.I'm obligated to ask this question of Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

Correct choice is (b) O(N log n)

The explanation is: Worst CASE TIME complexity of quicksort is AVOIDED when we implement introsort. Introsort switches to heap sort when there is a possibility of crossing the MAXIMUM depth limit.

245.

What is the best case time complexity of introsort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)The question was posed to me in my homework.Query is from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

The CORRECT choice is (B) O(n LOG n)

Easy explanation - Introsort is mainly governed by HEAP sort and QUICK sort. As the best case of both heap sort and quick sort is O(n log n) so the best case of introsort also becomes O(n log n).

246.

Introsort sort is a comparison based sort.(a) true(b) falseI got this question in an online quiz.I would like to ask this question from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Right answer is (a) true

To explain: QUICKSORT, HEAP sort and insertion sort are COMPARISON based sorts. Thus OVERALL introsort also becomes a comparison based sort.

247.

Which of the following sorting algorithm is in-place?(a) intro sort(b) merge sort(c) counting sort(d) radix sortThe question was posed to me in an interview for internship.The question is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer» CORRECT option is (a) intro sort

For explanation: INTROSORT may use quick sort or heap sort or insertion sort internally in order to sort the GIVEN INPUT. All of the three algorithms are in PLACE, thus making introsort to be an in-place sorting algorithm.
248.

Which of the following sorting algorithm is NOT stable?(a) Introsort(b) Brick sort(c) Bubble sort(d) Merge sortThis question was addressed to me in unit test.My enquiry is from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

Right option is (a) Introsort

Explanation: Out of the GIVEN options introsort is the only algorithm which is not stable. As it MAY USE QUICK sort in some CASE to perform sorting which is itself not stable. Thus stability of introsort is not guaranteed.

249.

Introsort begins sorting the given array by using which of the following sorting algorithm?(a) selection sort(b) quick sort(c) insertion sort(d) heap sortI have been asked this question in final exam.Question is taken from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct choice is (B) QUICK sort

For explanation: Introsort begins sorting any given ARRAY by using quick sort. Then it may switch to heap sort or insertion sort or may stick to quick sort depending upon the size of the partition.

250.

Which of the following sorting algorithm is used by C++ internally?(a) quicksort(b) introsort(c) merge sort(d) heap sortThe question was asked during a job interview.I'm obligated to ask this question of Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

Right option is (B) INTROSORT

Easy EXPLANATION - Introsort is the in built sorting algorithm used by C++. It is an EXAMPLE of a hybrid sorting algorithm which means it uses more than one sorting algorithm as a routine.