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.

151.

What is the worst case time complexity of comb sort?(a) O(n^2)(b) O(n log n)(c) O(n)(d) O(n^2/2^a) (a=number of increment)I had been asked this question in homework.This is a very interesting question from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

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

The best I can explain: Worst CASE complexity is observed when the INPUT array is reverse sorted. This is same as the worst case complexity of bubble SORT.

152.

The initial gap between two elements being compared _______(a) is equal to number of elements in the array(b) is equal to 1.3(c) depends on the number of iterations(d) depends on the compiler being usedI have been asked this question during an interview.My enquiry is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

The CORRECT option is (a) is equal to NUMBER of elements in the array

The best I can explain: INITIAL gap is TAKEN to be equal to the number of elements in the array and shrinks by a factor of 1.3 in each iteration, initial gap is independent of the number of ITERATIONS and compiler being used.

153.

The gap between two elements being compared shrinks by a factor of _______ after every iteration.(a) 1.1(b) 1.2(c) 1.3(d) 1.4This question was addressed to me in an interview for job.I need to ask this question from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

The correct CHOICE is (c) 1.3

Easy explanation - It has been found EXPERIMENTALLY that the gap between the TWO ELEMENTS should shrink by a factor of 1.3 after each iteration for the most efficient sorting.

154.

Comb sort is an improved version of _______(a) Selection sort(b) Bubble sort(c) Insertion sort(d) Merge sortI had been asked this question in quiz.This question is from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The CORRECT option is (b) Bubble sort

The BEST I can explain: Comb sort compares TWO elements at a VARIABLE gap from each other in each iteration unlike bubble sort where the gap REMAINS 1. This reduces the average time complexity of comb sort.

155.

Bubble sort performs better as compared to cocktail sort.(a) True(b) FalseThe question was posed to me by my school teacher while I was bunking the class.I would like to ask this question from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Correct CHOICE is (b) False

The BEST EXPLANATION: Both BUBBLE sort and cocktail sort has the same time complexities. But cocktail sort has a comparatively better performance.

156.

How many iterations are required to sort the array arr={2,3,4,5,1} using bubble sort and cocktail sort respectively?(a) 4,2(b) 5,3(c) 5,2(d) 4,3The question was posed to me at a job interview.Asked question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

The CORRECT choice is (a) 4,2

The best explanation: Cocktail sort applies bubble sort in two phases until the array GETS SORTED. So here bubble sort will take 4 iterations to sort the given array WHEREAS cocktail sort takes only 2 iterations. This shows cocktail sort has a comparatively better PERFORMANCE.

157.

What is the average case time complexity of odd-even sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)I had been asked this question in final exam.The doubt is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

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

For explanation: Cocktail sort takes O(n^2) time on AVERAGE as it KEEPS on applying bubble sort on the elements in TWO phases until they are sorted. This is the same as the average time complexity of bubble sort.
158.

What is the best case time complexity of cocktail sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)I got this question during an interview for a job.My doubt stems from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

The correct OPTION is (a) O(N)

The explanation is: Best case complexity is OBSERVED when the input array is ALREADY sorted. This is the same as the best case complexity of bubble SORT.

159.

What is the worst case time complexity of cocktail sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)I have been asked this question during a job interview.I would like to ask this question from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Right CHOICE is (c) O(n^2)

EXPLANATION: Worst case COMPLEXITY is observed when the input array is reverse SORTED. This is the same as the worst case complexity of bubble sort.

160.

Cocktail sort uses which of the following methods for sorting the input?(a) selection(b) partitioning(c) merging(d) exchangingI got this question at a job interview.My question is taken from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer» CORRECT answer is (d) exchanging

To explain: Cocktail sort USES a method of exchanging as it swaps the elements which are out of order. This SWAPPING is done in two phases i.e. FORWARD phase and BACKWARD phase.
161.

Cocktail sort is a comparison based sort.(a) True(b) FalseThe question was asked in an interview for job.My question comes from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The correct OPTION is (a) True

For explanation: Cocktail SORT compares the value of DIFFERENT elements in the array for SORTING. Thus, it is a comparison based sort.

162.

Which of the following sorting algorithm is in place?(a) cocktail sort(b) merge sort(c) counting sort(d) radix sortThe question was asked in exam.My enquiry is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct option is (a) cocktail sort

The EXPLANATION is: Cocktail sort is an in PLACE SORTING technique as it only requires constant AUXILIARY space for manipulating the INPUT array. Rest all other options are not in place.

163.

Which of the following sorting algorithm is NOT stable?(a) Quick sort(b) Cocktail sort(c) Bubble sort(d) Merge sortThe question was asked at a job interview.The doubt is from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer» RIGHT CHOICE is (a) Quick sort

Easy explanation - Out of the given options quick sort is the only algorithm which is not stable. Cocktail sort LIKE BUBBLE sort is a stable sorting algorithm.
164.

Auxiliary space requirement of cocktail sort is _____________(a) O(n)(b) O(log n)(c) O(1)(d) O(n^2)I have been asked this question in an internship interview.This intriguing question originated from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Right CHOICE is (c) O(1)

Best explanation: In COCKTAIL sort manipulation is done on the input array itself. So no extra space is REQUIRED to perform sorting. Thus it requires CONSTANT auxiliary space.

165.

Cocktail sort is a variation of _____________(a) Bubble sort(b) Selection sort(c) Insertion sort(d) Gnome sortI got this question in my homework.Asked question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Right ANSWER is (a) Bubble sort

To EXPLAIN: Cocktail sort is very similar to bubble sort. It WORKS by traversing an array in both directions alternatively. It compares the adjacent ELEMENTS in each iteration and SWAPS the ones which are out of order.

166.

Cocktail sort is also known as ________________(a) bidirectional sort(b) bubble sort(c) brick sort(d) ripple sortI got this question by my school principal while I was bunking the class.My doubt is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct choice is (d) ripple sort

For explanation: Cocktail sort is ALSO known by the name of ripple sort. It is also known by other NAMES LIKE – bidirectional bubble sort, cocktail shaker sort, shuttle sort, SHUFFLE sort etc.

167.

Which of the following is an adaptive sorting algorithm?(a) heap sort(b) strand sort(c) selection sort(d) merge sortThe question was posed to me at a job interview.The above asked question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct ANSWER is (b) STRAND sort

For explanation: Strand sort is an adaptive sorting algorithm. This is because it gives a better performance when the input LIST is almost SORTED.

168.

Strand sort algorithm used which of the following method for sorting a list?(a) merging(b) selection(c) insertion(d) partitioningI have been asked this question in class test.This interesting question is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

The CORRECT ANSWER is (b) SELECTION

Easiest EXPLANATION - Strand sort uses the method of selection for sorting any given list. This is because it SELECTS the strands of elements from the input list which are sorted.

169.

What is the worst case time complexity of strand sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(n^2 log n)The question was asked in an interview for job.My question is taken from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer» CORRECT option is (C) O(n^2)

EASY explanation - WORST CASE time complexity of strand sort is O(n^2). It occurs in the case where the input array is in reverse sorted order.
170.

What is the best case time complexity of strand sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(n^2 log n)I got this question in an internship interview.This intriguing question originated from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

Correct ANSWER is (a) O(n)

Best explanation: Best case TIME complexity of STRAND sort is O(n). It occurs in the case where the INPUT array is ALREADY sorted.

171.

What is the average time complexity of strand sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(n^2 log n)I got this question in an internship interview.This key question is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Correct CHOICE is (c) O(n^2)

The explanation is: Average case time complexity of strand SORT is O(N2). So it is not as EFFICIENT as quick sort or merge sort.

172.

Strand sort is a stable sorting algorithm.(a) true(b) falseThe question was asked at a job interview.I want to ask this question from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Correct OPTION is (a) true

The explanation is: STRAND sort is an example of a stable SORTING algorithm. It is because the elements with IDENTICAL values APPEAR in the same order in the output array as they were in the input array.

173.

Strand sort is a comparison based sorting algorithm.(a) true(b) falseI have been asked this question in exam.Enquiry is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Right OPTION is (a) true

To EXPLAIN: Pigeonhole sort is an example of a comparison based SORTING algorithm. This is because it COMPARES the value of elements present in a list in ORDER to sort them.

174.

Which of the following sorting algorithm is not in place?(a) quick sort(b) strand sort(c) cycle sort(d) heap sortI had been asked this question in homework.The origin of the question is Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Right OPTION is (B) STRAND sort

To EXPLAIN: Strand sort has an auxiliary space complexity of O(n). So it is not an in place sorting algorithm.

175.

What is the auxiliary space complexity of strand sort?(a) O(n)(b) O(1)(c) O(log n)(d) O(n log n)I got this question during an internship interview.I want to ask this question from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

The CORRECT option is (a) O(n)

EXPLANATION: The AUXILIARY space complexity of STRAND sort is O(n). It is because a sub-list of size n has to be maintained.

176.

In which of the following case strand sort is most efficient?(a) when input array is already sorted(b) when input array is reverse sorted(c) when input array is large(d) when input array is has randomly spread elementsThe question was posed to me during an internship interview.The doubt is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer» RIGHT option is (a) when input array is ALREADY sorted

For EXPLANATION: The best CASE of strand sort occurs when the input array is already sorted. In this case, it has linear TIME complexity.
177.

Strand sort is most efficient for data stored in?(a) linked list(b) arrays(c) trees(d) graphsThe question was posed to me in class test.Enquiry is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer» CORRECT choice is (a) linked list

Explanation: Strand sort is most EFFICIENT when data is STORED in a linked list as it involves many insertions and deletions which is performed quite efficiently with the help of a linked list. Using an array would INCREASE time COMPLEXITY significantly.
178.

Which one of the following sorting algorithm requires recursion?(a) pigeonhole sort(b) strand sort(c) insertion sort(d) counting sortThe question was asked in unit test.Question is taken from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (b) strand SORT

Best explanation: Strand sort REQUIRES the use of RECURSION for implementing its algorithm. On the other hand, the sorting ALGORITHMS given in the remaining options use ITERATIVE methods.

179.

Which of the following is not true about library sort?(a) it uses binary search and insertion sort in its implementation(b) gaps are created between successive elements in order to ensure faster insertion(c) array needs to be re balanced after every insertion(d) it is an in place sorting algorithmI have been asked this question by my college professor while I was bunking the class.Query is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

Right choice is (d) it is an in PLACE sorting algorithm

Easy EXPLANATION - Library sort is not an in place sorting algorithm as it requires O(n) auxiliary SPACE. The array needs to be re balanced after every insertion so as to ensure that GAPS are present between every successive element.

180.

Which of the following sorting algorithm is not in place?(a) library sort(b) quick sort sort(c) heap sort(d) gnome sortThe question was asked in an interview.The origin of the question is Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct option is (a) LIBRARY SORT

For EXPLANATION: Out of the given options library sort is the only algorithm which is not in place. It is because the auxiliary SPACE required by library sort is O(N).

181.

Which of the following is an adaptive sorting algorithm?(a) library sort(b) merge sort(c) heap sort(d) selection sortI have been asked this question in a job interview.I'm obligated to ask this question of Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Right OPTION is (a) library sort

Easiest explanation - Library sort is an adaptive algorithm. It is because the TIME complexity of the algorithm improves when the INPUT array is ALMOST sorted.

182.

What is the auxiliary space complexity of library sort?(a) O(n)(b) O(1)(c) O(n log n)(d) O(n^2)I got this question in an online quiz.Enquiry is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer» CORRECT option is (a) O(N)

Easy explanation - The auxiliary space required by library SORT is O(n). This space is taken up by the GAPS PRESENT in between successive elements.
183.

What is the advantage of library sort over insertion sort?(a) Library sort has a better average time complexity(b) Library sort has a better space complexity(c) Library sort has better best case time complexity(d) Library has better worst case time complexityThis question was posed to me in an online interview.This key question is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Correct choice is (a) Library sort has a BETTER average time complexity

Best explanation: Library sort has a better average time complexity as COMPARED to insertion sort because it USES binary search for finding the index where the ELEMENT has to be inserted in the sorted ARRAY. This makes the process faster.

184.

Which of the following is an alternate name of library sort?(a) gapped insertion sort(b) binary insertion sort(c) recursive insertion sort(d) binary gap sortI got this question in an interview for job.This interesting question is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

The correct ANSWER is (a) gapped insertion sort

The best explanation: Library sort is also KNOWN as gapped insertion sort because it uses insertion sort with GAPS in between SUCCESSIVE ELEMENTS. These gaps allow for fast insertion.

185.

What is the worst case time complexity of library sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)This question was addressed to me in an international level competition.This intriguing question comes from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

The correct OPTION is (c) O(n^2)

Easiest EXPLANATION - The worst case TIME complexity of library sort is the same as that of INSERTION sort. The worst case time complexity is O(n^2).

186.

What is the best case time complexity of library sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)The question was posed to me during an interview.This interesting question is from Sorting in chapter Sorting of Data Structures & Algorithms II

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

For explanation: The best case time COMPLEXITY of library SORT is O(n). It occurs in the case when the input is already/almost sorted.
187.

What is the average case time complexity of library sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)I had been asked this question in homework.I would like to ask this question from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

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

Easiest EXPLANATION - Library sort USES BINARY search in order to insert elements in the sorted segment of the array which reduces its TIME complexity. So the average time complexity of library sort is O(n log n).

188.

Library sort is a comparison based sort.(a) true(b) falseThis question was addressed to me in my homework.My question is based upon Sorting topic in division Sorting of Data Structures & Algorithms II

Answer» CORRECT choice is (a) true

Easy EXPLANATION - In library sort, we need to compare elements in order to insert them at the correct index. So we can say that it uses comparisons in order to sort the ARRAY. THUS it qualifies as a COMPARISON based sort.
189.

Which of the following sorting algorithm requires the use of binary search in their implementation?(a) radix sort(b) library sort(c) odd-even sort(d) bead sortI got this question during a job interview.Asked question is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

Correct choice is (b) library sort

The best I can explain: Library sort makes use of a binary SEARCH algorithm. It is used to FIND the correct INDEX in the array where the element should be inserted. Then after the INSERTION of the element re-balancing of the array TAKES place.

190.

Which of the following sorting algorithm is stable?(a) Selection sort(b) Quick sort(c) Library sort(d) Heap sortThis question was posed to me in an internship interview.The query is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

Correct OPTION is (C) Library sort

For explanation: Out of the given options library sort is the only algorithm which is stable. It is because the elements with IDENTICAL values appear in the same ORDER in the output array as they were in the input array.

191.

Library sort is a modified version of which of the following sorting algorithm?(a) Bubble sort(b) selection sort(c) insertion sort(d) quick sortI got this question in final exam.I'm obligated to ask this question of Sorting in section Sorting of Data Structures & Algorithms II

Answer» CORRECT choice is (c) INSERTION sort

To EXPLAIN: LIBRARY sort requires the use of Insertion sort and BINARY search in its code. So it is a modified version of insertion sort.
192.

Library sort is an online sorting algorithm.(a) true(b) falseThis question was posed to me during a job interview.This is a very interesting question from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

Correct choice is (a) true

Easy explanation - Library sort does not require the entire input DATA at the BEGINNING itself in order to sort the array. It rather creates a partial solution in every step, so FUTURE elements are not required to be considered. Hence it is an online sorting algorithm like INSERTION sort.

193.

Which of the following is a disadvantage of library sort when compared to insertion sort?(a) library sort has greater time complexity(b) library sort has greater space complexity(c) library sort makes more comparisons(d) it has no significant disadvantageThis question was addressed to me in exam.This intriguing question originated from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

Correct OPTION is (b) library sort has greater SPACE complexity

The explanation is: Library sort has a DISADVANTAGE that it takes up O(n) AUXILIARY space whereas insertion sort takes constant auxiliary space.

194.

Which of the following algorithm is best suited for the case where swap operation is expensive?(a) bubble sort(b) cycle sort(c) cocktail sort(d) merge sortI got this question during an internship interview.Origin of the question is Sorting in division Sorting of Data Structures & Algorithms II

Answer» RIGHT choice is (b) cycle SORT

Easy EXPLANATION - Cycle sort is a slow sorting algorithm but it requires a minimum number of write operations in ORDER to sort a given ARRAY. So it is useful when the write/swap operation is expensive.
195.

How many write operations will be required to sort the array arr={2,4,3,5,1} using cycle sort?(a) 4(b) 5(c) 6(d) 3This question was addressed to me during an online interview.Asked question is from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (a) 4

The best I can explain: CYCLE sort requires a minimum number of write OPERATIONS in order to sort a GIVEN array. So in this CASE, only 4 write operations will be required.

196.

Which of the following sorting algorithm uses the method of insertion?(a) cycle sort(b) bubble sort(c) quick sort(d) selection sortI have been asked this question in unit test.My question is taken from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

Right answer is (a) cycle sort

The BEST I can EXPLAIN: Cycle sort is the only ALGORITHM from the given ONES that uses the METHOD of insertion. Other than this, insertion sort also uses the method of insertion for sorting.

197.

Cycle sort is a comparison based sort.(a) true(b) falseThis question was posed to me in an interview for job.The origin of the question is Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

Correct option is (a) true

Easiest EXPLANATION - Cycle sort is a comparison BASED SORTING algorithm. This is because it COMPARES elements in order to sort them.

198.

Which of the following is an advantage of cycle sort?(a) it can sort large arrays efficiently(b) it has a low time complexity(c) it requires minimal write operations(d) it is an adaptive sorting algorithmThis question was addressed to me by my school teacher while I was bunking the class.My doubt stems from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

Right choice is (c) it REQUIRES minimal write operations

The EXPLANATION is: Cycle sort is a slow sorting algorithm as compared to quick sort, merge sort etc. and is ALSO not adaptive. But it offers an advantage that it PERFORMS minimal write operations which can be very useful in a situation where the write operation is expensive.

199.

Which of the following sorting algorithm is in-place?(a) Merge sort(b) Cycle sort(c) Counting sort(d) Radix sortThis question was addressed to me during a job interview.My question is based upon Sorting in division Sorting of Data Structures & Algorithms II

Answer» RIGHT OPTION is (b) Cycle sort

Best EXPLANATION: Cycle sort has an auxiliary SPACE COMPLEXITY of O(1). So it qualifies to be an in-place sort. All other given options are not in place sorting algorithm.
200.

Cycle sort is an adaptive sorting algorithm.(a) true(b) falseThe question was asked in examination.Query is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer» CORRECT OPTION is (b) false

Easy EXPLANATION - The time complexity of CYCLE sort is O(n^2) in any case. So cycle sort algorithm is not adaptive, as it will take the same time to sort an already sorted array and any other randomly ARRANGED array.