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.

101.

Which of the following is an alternate name of MSD radix sort?(a) bottom up radix sort(b) top down radix sort(c) forward radix sort(d) backward radix sortI got this question by my college director while I was bunking the class.The above asked question is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer» CORRECT answer is (b) TOP down radix sort

Explanation: Top down radix sort is an ALTERNATE name of MSD radix sort. It is because in this ALGORITHM the processing starts from the most significant digit and end at least significant digit.
102.

Which of the following is the most suitable definition of radix sort?(a) It is a non comparison based integer sort(b) It is a comparison based integer sort(c) It is a non comparison based non integer sort(d) It is a comparison based non integer sortThis question was posed to me in unit test.This key question is from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

Right answer is (a) It is a non comparison based integer sort

The explanation is: Radix sort is a non-comparison based integer sort. It SORTS the given data by GROUPING KEYS which share the same SIGNIFICANT position VALUE.

103.

Which of the following combines qualities of MSD radix sort and LSD radix sort?(a) in-place MSD radix sort(b) stable MSD radix sot(c) 3 way radix quick sort(d) forward radix sortThis question was posed to me during an online interview.This interesting question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct ANSWER is (d) FORWARD radix SORT

The explanation is: Forward radix sort combines the QUALITIES of MSD and LSD radix sort. The sorting is done by separating the strings into groups.

104.

What is the full form of MSD in MSD radix sort?(a) most significant digit(b) many significant digit(c) more significant digit(d) must significant digitThis question was posed to me in an interview.I need to ask this question from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

Right option is (a) most SIGNIFICANT digit

To explain: MSD stands for Most Significant Digit. It is named so because in this ALGORITHM the PROCESSING begins from the most significant digit.

105.

How many comparisons will be made to sort the array arr = {1, 5, 3, 8, 2} using MSD radix sort?(a) 5(b) 7(c) 9(d) 0I got this question in an interview for internship.My question is taken from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

Right option is (d) 0

Easiest explanation - As MSD RADIX sort is an EXAMPLE of non comparison sort so it is able to sort an array WITHOUT making any comparison. So the answer should be 0.

106.

LSD radix sort is in-place sorting algorithm.(a) False(b) TrueI got this question in a national level competition.The above asked question is from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

Right option is (a) False

The best explanation: LSD radix is not an in-place sorting algorithm. It needs extra memory to STORE the elements in bucket and its worst case space complexity is O(W + R).

107.

Which of the following is true for the LSD radix sort?(a) works best for variable length strings(b) accesses memory randomly(c) inner loop has less instructions(d) sorts the keys in left-to-right orderThe question was posed to me in examination.My query is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer» RIGHT choice is (b) accesses memory randomly

The explanation is: LSD radix sort SORTS the keys in right-to-left order, working with Least Significant Digit first. The inner LOOP has a lot of instructions and LSD radix sort is USED to sort fixed-length strings.
108.

Which of the following is a combination of LSD and MSD radix sorts?(a) Forward radix sort(b) 3-way radix quick sort(c) Trie base radix sort(d) Flash sortThe question was posed to me in a job interview.My question is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Right answer is (a) FORWARD radix sort

Easy explanation - Forward radix sort COMBINES the advantages of LSD and MSD radix sort. Forward radix sort INSPECTS a COMPLETE horizontal strip at a time just like LSD radix sort.

109.

Which of the following should be used to sort a huge database on a fixed-length key field?(a) Insertion sort(b) Merge sort(c) LSD radix sort(d) Quick sortThis question was addressed to me during an online exam.This interesting question is from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The CORRECT ANSWER is (c) LSD radix SORT

For explanation: LSD radix requires only w passes to sort a fixed-LENGTH string, where w is a length of the strings. So, LSD radix sort is best suited to sort a huge database on a fixed-length key FIELD.

110.

LSD radix sort is faster than comparison sorts.(a) True(b) FalseI had been asked this question in an international level competition.This key question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (b) False

The BEST I can explain: LSD radix sort is faster than comparison SORTS when the word size is LESS than logn. But LSD radix sort runs slowly for elements with larger word size and SMALLER radix.

111.

Which of the following sorting algorithm is stable?(a) Heap sort(b) Selection sort(c) In-place MSD radix sort(d) LSD radix sortThe question was posed to me in an online interview.My question is taken from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Right answer is (d) LSD radix sort

Easiest explanation - In LSD radix sort after sorting the MULTIPLE ELEMENTS with the same key will be in the same ORDER as they were in the INPUT array. So LSD radix sort is stable sort.

112.

Which of the following is false?(a) LSD radix sort is an integer sorting algorithm(b) LSD radix sort is a comparison sorting algorithm(c) LSD radix sort is a distribution sort(d) LSD radix sort uses bucket sortI had been asked this question in quiz.My question is taken from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (b) LSD radix SORT is a COMPARISON sorting algorithm

The EXPLANATION is: LSD radix sort uses bucket sort for GROUPING the KEYS based on the digits at that value. And as it grouped the keys based on the digits at that values, it is integer sorting algorithm.

113.

LSD radix sort requires _____ passes to sort N elements.(a) (w/logR)(b) N(w/logR)(c) (w/log(RN))(d) (wN/log(N))I have been asked this question by my college director while I was bunking the class.My question comes from Sorting in portion Sorting of Data Structures & Algorithms II

Answer» RIGHT option is (a) (W/logR)

The best I can explain: LSD radix sort sorts the N elements in(w/logR) passes where w is the number of digits in largest number and R(radix) is extra space required for performing the SORTING OPERATION.
114.

What is the worst case time complexity of LSD radix sort?(a) O(nlogn)(b) O(wn)(c) O(n)(d) O(n + w)I got this question in a job interview.Query is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Right choice is (b) O(wn)

Easiest explanation - Time COMPLEXITY of LSD radix sort DEPENDS UPON the word SIZE and the number on items. It runs in O(wn) time in worst case, where n is the number of inputted elements and W is the number of digits in the largest number.

115.

Which of the following is the distribution sort?(a) Heap sort(b) Smooth sort(c) Quick sort(d) LSD radix sortThis question was addressed to me by my college director while I was bunking the class.I want to ask this question from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

Correct CHOICE is (d) LSD radix sort

The best explanation: In Distribution sort the inputted values are distributed to multiple INTERMEDIATE STRUCTURES which are then combined and placed on the OUTPUT. And LSD radix sort distributes values into buckets based on the digits within values, so it is a distribution sort.

116.

What is the average time complexity of pigeonhole sort (k=range of input)?(a) O(n)(b) O(n+k)(c) O(n^2)(d) O(n*k)The question was asked in examination.Asked question is from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

The CORRECT answer is (b) O(N+k)

The explanation is: Time COMPLEXITY of pigeonhole sort is O(n+k). It has two loops. ONE of the loops runs from 0 to range(k) and the other one runs from 0 to n so the time complexity becomes O(n+k).

117.

Pigeonhole sort is an in place sorting algorithm.(a) true(b) falseThis question was posed to me during an interview for a job.This interesting question is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct option is (b) false

Easy EXPLANATION - PIGEONHOLE sort requires space of O(n+k). So it does not qualify to be an in PLACE SORTING ALGORITHM.

118.

Pigeonhole sort is a stable sorting algorithm.(a) true(b) falseI have been asked this question in exam.The query is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct OPTION is (a) true

The best I can explain: PIGEONHOLE 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.

119.

The auxiliary array used in pigeonhole sorting is called ______________(a) bucket(b) pigeon(c) hole(d) pigeonholeThe question was posed to me by my school teacher while I was bunking the class.Question is taken from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

The correct OPTION is (d) pigeonhole

Easiest explanation - The auxiliary ARRAY used in pigeonhole SORTING is called pigeonhole. It is used to store every element in its CORRESPONDING hole.

120.

What is the space complexity of pigeonhole sort (k=range of input)?(a) O(n*k)(b) O(n)(c) O(k)(d) O(n+k)I had been asked this question in an internship interview.My enquiry is from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Right choice is (d) O(n+k)

Best explanation: PIGEONHOLE sort algorithm requires two arrays. The FIRST one is REQUIRED to store the input elements so its size is n. The second one is the pigeonhole array and has a size equal to range k. OVERALL space complexity BECOMES O(n+k).

121.

In which of the following case pigeonhole sort is most efficient?(a) when range of input is less than number of elements(b) when range of input is more than number of elements(c) when range of input is comparable to the number of elements(d) when the given array is almost sortedI had been asked this question during an online exam.Question is taken from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

The CORRECT choice is (c) when range of input is COMPARABLE to the NUMBER of elements

Explanation: Pigeonhole sort is a non-comparison BASED sort. It is most efficient in the case where the number of elements are comparable to the input range.

122.

Which of the following is a non-comparison sort?(a) heap sort(b) quick sort(c) merge sort(d) pigeonhole sortThe question was posed to me in an interview for internship.Question is from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

The correct option is (d) pigeonhole sort

To EXPLAIN: Heap sort, merge sort and quick sort are EXAMPLES of comparison sort as it NEEDS to compare ARRAY elements in order to sort an array. Whereas pigeonhole sort is a non-comparison based sort.

123.

How many comparisons will be made to sort the array arr={1,5,3,8,2} using pigeonhole sort?(a) 5(b) 7(c) 9(d) 0The question was asked in final exam.This intriguing question originated from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Correct CHOICE is (d) 0

The best I can explain: As PIGEONHOLE sort is an example of a non-comparison sort so it is able to sort an ARRAY WITHOUT making any comparison. So 0 comparisons are required.

124.

Sleep sort is an in-place sorting technique.(a) True(b) FalseThis question was addressed to me by my school principal while I was bunking the class.I need to ask this question from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

Right option is (a) True

The explanation is: Sleep SORT is an in-PLACE sorting technique as most of its major steps takes place in the BACKGROUND. So it does not REQUIRE auxiliary space to sort the input.

125.

Which of the following sorting algorithm is most closely related to the OS?(a) gnome sort(b) sleep sort(c) radix sort(d) bogo sortI had been asked this question in unit test.My question is taken from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Right answer is (b) SLEEP SORT

The best explanation: Sleep sort is most closely related to the operating system. It is because most of the major STEPS of this algorithm TAKES place at the core of OS.

126.

Sleep sort does gives a correct output when ___________(a) any input element is negative(b) input array is reverse sorted(c) any input element is positive(d) when there is a very small number to the left of very large numberI have been asked this question by my college professor while I was bunking the class.My query is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

The CORRECT CHOICE is (C) any input element is positive

Easy explanation - Sleep sort gives a sorted output when the array elements are positive. But when any other case than this occur out of the above GIVEN cases then we MAY not see a correct output. This makes sleep sort very unreliable sorting technique.

127.

Auxiliary space requirement of sleep sort is ___________(a) O(n)(b) O(1)(c) O(max(input))(d) O(log n)I had been asked this question by my college professor while I was bunking the class.I'd like to ask this question from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (b) O(1)

Explanation: All the MAJOR PROCESSES involved in sleep SORT TAKES place internally in the OS. So it does not require any auxiliary space to sort the ELEMENTS.

128.

Sleep sort can be preferred over which of the following sorting algorithms for large number of input elements?(a) Quick sort(b) Bubble sort(c) Selection sort(d) No sorting algorithm is preferredThis question was addressed to me in a national level competition.My question comes from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct OPTION is (d) No SORTING algorithm is preferred

The best I can explain: Sleep SORT is not preferred over any of the given sorting algorithms as sleep sort does not guarantee a correct OUTPUT every time. So sleep sort is not a RELIABLE sorting technique.

129.

Time complexity of sleep sort can be approximated to be ___________(a) O(n + max(input))(b) O(n^2)(c) O(n log n + max(input))(d) O(n log n)The question was posed to me in semester exam.Question is from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

Right choice is (c) O(n log n + MAX(input))

EXPLANATION: As the SLEEP() function creates multiple THREADS by using PRIORITY queue which takes n log n time for insertion. Also the output is obtained when all the elements wake up. This time is proportional to the max(input). So its time complexity is approximately O(n log n + max(input)).

130.

Sleep sort code cannot compile online because ___________(a) it has very high time complexity(b) it has very high space complexity(c) it requires multithreading process(d) online compilers are not efficientThe question was posed to me in unit test.My question is based upon Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

The CORRECT answer is (C) it requires multithreading process

The explanation is: Sleep sort requires multithreading process for making the elements to sleep. This process happens in the background at the core of the OS and so cannot be COMPILED on an online compiler.

131.

Sleep sort works by ___________(a) making elements to sleep for a time that is proportional to their magnitude(b) making elements to sleep for a time that is inversely proportional to their magnitude(c) partitioning the input array(d) dividing the value of input elementsThe question was posed to me in exam.Asked question is from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The CORRECT option is (a) making elements to SLEEP for a time that is proportional to their magnitude

Explanation: In sleep sort each element is made to sleep for a time that is proportional to its magnitude. Then the elements are PRINTED in the order in which they WAKE up.

132.

In how many comparisons does the array arr={1,4,2,3,5} gets sorted if we use sleep sort?(a) 5(b) 3(c) 1(d) 0The question was asked during an interview for a job.My doubt is from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

Right option is (d) 0

Best explanation: SLEEP SORT makes DIFFERENT elements of the array to sleep for an amount of time that is PROPORTIONAL to its MAGNITUDE. So it does not require to perform any comparison in order to sort the array.

133.

Sleep sort does not work for ___________(a) negative numbers(b) large numbers(c) small numbers(d) positive numbersThe question was posed to me at a job interview.Question is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Right choice is (a) negative NUMBERS

Easiest EXPLANATION - Sleep sort algorithm does not WORK for negative numbers. It is because thread cannot sleep for negative amount of TIME.

134.

Which of the following header file is a must to implement sleep sort algorithm?(a) string.h(b) math.hw(c) bios.h(d) windows.hThis question was addressed to me during an interview.My question is taken from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer» CORRECT CHOICE is (d) windows.h

The explanation is: To implement sleep sort algorithm we NEED functions like WaitForMultipleObjects(), _beginthread(). These are INCLUDED in the header FILE windows.h.
135.

What is the worst case time complexity of bogosort?(a) O(n^2)(b) O(n*n!)(c) O(infinity)(d) O(n log n)This question was addressed to me in an interview for internship.My doubt is from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

The correct option is (c) O(infinity)

For EXPLANATION: There is no upper bound to the worst case of this ALGORITHM. It can go on to TAKE very large amount of time if the array has many elements. So the worst case of this algorithm can be TAKEN as O(infinity).

136.

What is the best case time complexity of bogosort?(a) O(n^2)(b) O(n)(c) O(n log n)(d) O(1)The question was asked in an international level competition.My question is based upon Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

Correct ANSWER is (b) O(n)

Easiest explanation - Best case TIME complexity of BOGOSORT occurs when the input ARRAY is already sorted. So in such a case we only need to check whether all the elements are sorted which can be done in O(n) time.

137.

What is the auxiliary space requirement of bogosort?(a) O(n)(b) O(1)(c) O(log n)(d) O(n log n)I had been asked this question by my school principal while I was bunking the class.Asked question is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (b) O(1)

EXPLANATION: Bogosort algorithm do not REQUIRE any extra space for SORTING the input array. Thus its AUXILIARY space requirement is O(1).

138.

Bogosort works by __________(a) generating random permutations of its input(b) partitioning the array(c) dividing the value of input elements(d) generating permutations according to the value of first element of arrayThe question was asked in examination.The query is from Sorting in section Sorting of Data Structures & Algorithms II

Answer» CORRECT choice is (a) generating random permutations of its INPUT

Explanation: Bogosort algorithm successively generates permutations of its input. This PROCESS is repeated until the sorted version of the ARRAY is FOUND.
139.

Which of the following is not an alternative name of bogosort?(a) stupid sort(b) permutation sort(c) donkey sort(d) monkey sortThe question was posed to me in an interview.This is a very interesting question from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

The correct option is (c) donkey sort

For EXPLANATION: BOGOSORT is also known by names LIKE stupid sort, monkey sort, permutation sort, slow sort and SHOTGUN sort.These names are particularly chosen due to its INEFFICIENT algorithm.

140.

What is the average case time complexity of gnome sort?(a) O(n)(b) O(n^2)(c) O(n log n)(d) O(log n)This question was posed to me in an interview for internship.This intriguing question comes from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (b) O(n^2)

To explain: In gnome SORT the loop has to take one step backwards EVERY time any adjacent pair of ELEMENTS is out of PLACE which causes it to have time complexity of O(n^2) on an average.

141.

Auxiliary space used by gnome sort is _________(a) O(1)(b) O(n)(c) O(log n)(d) O(n log n)I have been asked this question in an interview.This key question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Right CHOICE is (a) O(1)

To explain: Auxiliary space used by gnome SORT is O(1) as it does not use any EXTRA space for MANIPULATING the INPUT. Thus it also qualifies as an in place sorting algorithm.

142.

Which of the following pair of sorting algorithms are stable?(a) gnome sort and quick sort(b) merge sort and selection sort(c) gnome sort and merge sort(d) heap sort and merge sortI got this question by my college director while I was bunking the class.I'd like to ask this question from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Right OPTION is (c) gnome sort and merge sort

The best EXPLANATION: Gnome sort and merge sort are STABLE sorting algorithms as the elements with IDENTICAL values appear in the same order in the output array as they were in the input array when any of these sorting algorithms are implemented.

143.

How many loops are required to implement gnome sorting algorithm?(a) Single loop(b) 2 nested loops(c) 3 nested loops(d) It does not require any loopI had been asked this question in quiz.The query is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Right answer is (a) Single loop

The best I can explain: In this SORTING ALGORITHM the variable representing the INDEX number is not incremented in case the adjacent pair of ELEMENTS are out of place. In such a case its VALUE is decremented instead. Thus it is able to implement sorting using a single loop.

144.

Gnome sort is also called __________(a) Smart sort(b) Stupid sort(c) Bogo sort(d) Special sortI got this question in an international level competition.Query is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Right choice is (b) Stupid sort

Best EXPLANATION: GNOME sort was ORIGINALLY NAMED as stupid sort but later on it GOT renamed as gnome sort.

145.

What is the advantage of comb sort over merge sort?(a) Comb sort is an in place sorting algorithm(b) Comb sort is a stable sorting algorithm(c) Comb sort is more efficient(d) It has no advantageThe question was posed to me in class test.I'd like to ask this question from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer» RIGHT choice is (a) Comb sort is an in PLACE sorting algorithm

The best explanation: Comb sort does not require AUXILIARY space for manipulating input so it is an in place sorting algorithm but MERGE sort does require O(n) of auxiliary space which makes comb sort better in terms of space complexity.
146.

What is the best case time complexity of comb sort and bubble sort respectively?(a) O(n^2) and O(n log n)(b) O(n log n) and O(n)(c) O(n) and O(n^2)(d) O(n^2/2^a) (a=number of increment) and O(n^2)The question was posed to me in class test.My doubt is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

The correct OPTION is (b) O(n LOG n) and O(n)

Explanation: Best case complexity for comb SORT and bubble sort is O(n log n) and O(n) respectively. It occurs when the INPUT array is already sorted.

147.

Comb sort is a stable sorting algorithm.(a) True(b) FalseI have been asked this question in unit test.Enquiry is from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The CORRECT option is (b) False

Easy explanation - Comb sort is not a STABLE sorting ALGORITHM as it does not sort the REPEATED elements in the same ORDER as they appear in the input.

148.

The given array is arr={7,4,5,8,1,2}. The number of iterations required to sort the array using comb sort and bubble sort respectively will be _______(a) 7 and 8(b) 5 and 6(c) 5 and 5(d) 4 and 5I got this question in an interview for internship.The above asked question is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (d) 4 and 5

Best explanation: Comb sort takes 1 iteration LESS as compared to BUBBLE sort as it makes USE of variable GAP value WHEREAS bubble sort uses a constant gap value of 1.

149.

Auxiliary space used by comb sort is _______(a) O(1)(b) O(n)(c) O(log n)(d) O(n log n)I got this question in an interview for internship.This key question is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Right answer is (a) O(1)

The explanation is: Auxiliary space used by comb SORT is O(1) as it does not USE any extra space for MANIPULATING the input.

150.

The gap value after 3 iterations in an array with 6 elements will be _______(a) 4(b) 3(c) 2(d) 1This question was posed to me by my school principal while I was bunking the class.This key question is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

Right option is (c) 2

Easy EXPLANATION - Initially the GAP VALUE will be 6. For the first iteration, it will be 6/1.3=4 then 4/1.3=3 for second iteration and 3/1.3=2 for the third iteration.