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.

51.

Brick sort uses which of the following methods for sorting the input?(a) selection(b) partitioning(c) merging(d) exchangingI had been asked this question during an interview.My question is taken from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

Right CHOICE is (d) exchanging

Easy EXPLANATION - Brick sort uses the method of exchanging as it swaps the ELEMENTS which are out of order. This swapping is done in two PHASES i.e. ODD phase and even phase.

52.

Odd-even sort is a comparison based sort.(a) true(b) falseThe question was posed to me by my college professor while I was bunking the class.The above asked question is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

The CORRECT choice is (a) true

To explain: Odd-even sort COMPARES the value of different elements in the array for sorting. Thus, it is a COMPARISON BASED sort.

53.

Which of the following sorting algorithm is in place?(a) brick sort(b) merge sort(c) counting sort(d) radix sortThis question was posed to me during an interview.The query is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (a) BRICK SORT

The best EXPLANATION: Brick sort is an in place sorting technique as it only requires constant auxiliary space for manipulating the INPUT ARRAY.

54.

Which of the following sorting algorithm is NOT stable?(a) Quick sort(b) Brick sort(c) Bubble sort(d) Merge sortThis question was posed to me in homework.Question is taken from Sorting in section Sorting of Data Structures & Algorithms II

Answer» CORRECT OPTION is (a) Quick sort

Easiest explanation - Out of the given OPTIONS quick sort is the only algorithm which is not STABLE. BRICK sort like bubble sort is a stable sorting algorithm.
55.

Auxiliary space requirement of odd-even sort is ___________(a) O(n)(b) O(log n)(c) O(1)(d) O(n^2)I have been asked this question in my homework.My question is taken from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (c) O(1)

The explanation is: In odd-even SORT manipulation is DONE on the input ARRAY itself. So no extra space is required to perform SORTING. Thus it requires constant AUXILIARY space.

56.

Odd-even sort is a variation of ___________(a) Bubble sort(b) Selection sort(c) Insertion sort(d) Gnome sortI got this question in an internship interview.The above asked question is from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

The CORRECT choice is (a) Bubble sort

Easy explanation - Odd-EVEN sort is very similar to bubble sort. It works by applying bubble sort in two phases I.e odd PHASE and even phase. In odd phase bubble sort is applied on odd indexed ELEMENTS and in even phase bubble sort is applied on even indexed elements.

57.

Odd-even sort is also known as ____________(a) stupid sort(b) smart sort(c) brick sort(d) bogo sortThis question was addressed to me in an internship interview.This intriguing question originated from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Right choice is (C) brick SORT

The explanation is: Odd-even sort is also known by the name of a brick sort. This algorithm was first PROPOSED by Habermann in 1972 and was INITIALLY invented for parallel computation of local interconnection.

58.

The Pancake Problems (1975, 1979, 1973) did NOT involve which of the following people?(a) Bill Gates(b) Jacob Goodman(c) Christos Papadimitriou(d) John GoodmanI got this question by my school principal while I was bunking the class.My query is from Pancake Sort in division Sorting of Data Structures & Algorithms II

Answer»

Correct option is (d) John GOODMAN

Explanation: (Jacob Goodman – 1975) What is the MAXIMUM NUMBER of flips needed to SORT a permutation of [n] into ascending order?

(Bill Gates and Christos Papadimitriou – 1979) What is the maximum number of flips needed to sort a SIGNED permutation of [n] into ascending order with all positive signs?

59.

When we realize a specific implementation of a pancake algorithm, every move when we find the greatest of the sized array and flipping can be modeled through __________(a) Combinations(b) Exponential functions(c) Logarithmic functions(d) PermutationsI have been asked this question in an internship interview.This key question is from Pancake Sort topic in portion Sorting of Data Structures & Algorithms II

Answer»

Right answer is (d) PERMUTATIONS

Explanation: Here when we FLIPPING the array or stack, we have to take utmost priority to preserve the order of the list so that that sorting doesnt BECOME INVALID. Hence we use permutations, we are ensuring that order MATTERS.

60.

In a computational complexity theory, a problem with decision making is said to be NP-complete when it is both in NP and NP-hard. What does NP mean?(a) Non Polynomial time(b) Non-deterministic Probabilistic(c) Non-deterministic Polynomial time(d) Non Probabilistic timeI have been asked this question in examination.Query is from Pancake Sort in chapter Sorting of Data Structures & Algorithms II

Answer» RIGHT choice is (C) Non-deterministic POLYNOMIAL time

The best explanation: Although any given solution to an NP-complete problem can be validated quickly in polynomial time; there is no way to efficiently LOCATE a solution to begin with. The UNIQUE characteristic of NP-complete problems is that no fast solution to them is known and hence NP-complete problems are said to be non-deterministic polynomial time.
61.

In addition to the pancake sorting problem, there is the case of the burnt pancake problem in which we are dealing with pancakes (discs) that are burnt on one side only. In this case it is taken that the burnt side must always end up _______(a) Faced down(b) Faced up(c) It doesn’t matter(d) Both sides are burntThis question was posed to me at a job interview.I'm obligated to ask this question of Pancake Sort topic in division Sorting of Data Structures & Algorithms II

Answer»

Right choice is (a) FACED down

Best explanation: A varation of this PANCAKE is with burnt pancakes. Here each pancake has a burnt side and all pancakes MUST, in addition, end up with the burnt side on bottom. It is a more difficult version of the regular pancake PROBLEM.

62.

Pancake Sorting appears in which of the following?(a) Frequency Scaling(b) Storage Virtualization(c) Parallel Processing(d) Neural NetworkingI got this question in semester exam.This interesting question is from Pancake Sort topic in portion Sorting of Data Structures & Algorithms II

Answer» CORRECT CHOICE is (c) Parallel Processing

Easy EXPLANATION - Pancake Sorting finds APPLICATION in educational use not to mention parallel processing networks by PROVIDING optimal routing algorithms between networks.
63.

How many flips does the simplest of pancake sorting techniques require?(a) 3n−3 flips(b) 2n-4 flips(c) 2n-3 flips(d) 3n-2 flipsI got this question in class test.My question is based upon Pancake Sort topic in portion Sorting of Data Structures & Algorithms II

Answer» CORRECT answer is (c) 2n-3 flips

The best I can explain: The minimum number of flips required to sort any stack of n PANCAKES has been shown to lie between 1.087n and 1.636n. using average of that 1.36n and EXTRACTING that for values of n>1. We have 1.36, 2.72, 4.08 etc. This MATCHES best with 2n-3 which is equal to 1, 3, 5, 7, 9, etc. An upper bound of 2n-3 comes by iteratively using the next largest element in its correct place using two flips.
64.

What is the time complexity for a given pancake sort given it undergoes “n” flip operations?(a) O(n)(b) O(n^2)(c) O(n^3)(d) O(2n)This question was addressed to me during an online exam.My question is taken from Pancake Sort in section Sorting of Data Structures & Algorithms II

Answer»

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

Explanation: Most SORTING algorithms try to SORT making the least number of comparisons but in pancake sort we try to sort USING as few REVERSALS as possible. Because the total number of flip operations PERFORMED in a pancake sort is O(n), the overall time complexity is O(n^2).

65.

Which operation is most essential to the process of pancake sort?(a) Flip the given data(b) Find the largest of given data(c) Finding the least of given data(d) Inserting something into the given dataI had been asked this question in exam.I'd like to ask this question from Pancake Sort in portion Sorting of Data Structures & Algorithms II

Answer»

The CORRECT answer is (a) Flip the GIVEN data

Best explanation: When we use pancake sort, we sort the ARRAY to find the largest, and then flip the array at that point to bring that value to the bottom of the pancake stack. The SIZE of the array that we are dealing with is then reduced and the process continues. Flip operation is the most important function in the pancake sort technique.

66.

How many comparisons will be required to sort the array arr={5, 4, 7, 1, 9} using bead sort?(a) 5(b) 4(c) 6(d) 0This question was posed to me in unit test.My question is based upon Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (d) 0

Easiest explanation - Bead sort is an EXAMPLE of a non-comparison BASED sorting algorithm. So no comparison is required to be performed in order to sort the array.

67.

Bead sort is a comparison based sorting algorithm.(a) true(b) falseThis question was posed to me in semester exam.Query is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (b) false

To EXPLAIN: Bead sort is an example of NON comparison BASED sorting algorithm. This is because it does not compare the value of elements PRESENT in a list in order to sort them.

68.

Which of the following sorting algorithm is not in place?(a) quick sort(b) bead sort(c) cycle sort(d) heap sortThe question was asked during an online exam.I'd like to ask this question from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Correct option is (b) bead sort

To EXPLAIN: Bead sort has an AUXILIARY space COMPLEXITY of O(n2). So it is not an in PLACE sorting ALGORITHM.

69.

What is the auxiliary space complexity of bead sort?(a) O(n)(b) O(1)(c) O(n^2)(d) O(n log n)I got this question in semester exam.My question is based upon Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

The correct CHOICE is (C) O(n^2)

Best EXPLANATION: The auxiliary SPACE complexity of bead sort is O(n^2). It is because an array of size maximum_element*n (maximum_element is the maximum element that is present in the array and n is the size of the array) has to be maintained.

70.

Which of the following sorting algorithm is only applicable to positive integers?(a) quick sort(b) heap sort(c) bead sort(d) strand sortI have been asked this question in an internship interview.Origin of the question is Sorting topic in section Sorting of Data Structures & Algorithms II

Answer» CORRECT answer is (c) bead sort

To EXPLAIN: Bead sort algorithm is only applicable to positive INTEGERS. This is because it works by placing NUMBER of beads equal to key VALUE, in each row.
71.

Which of the following sorting algorithm was inspired by the natural phenomenon of falling objects?(a) bogo sort(b) heap sort(c) bead sort(d) strand sortThis question was posed to me during an interview for a job.I would like to ask this question from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

The correct ANSWER is (c) bead sort

For explanation: The algorithm of bead sort was INSPIRED by the natural phenomenon of FALLING objects. THUS, it is also known by the name of gravity sort.

72.

Bead sort is also known as _________(a) gravity sort(b) strand sort(c) abacus sort(d) counting sortThe question was asked in my homework.The query is from Sorting in section Sorting of Data Structures & Algorithms II

Answer» CORRECT option is (a) gravity sort

The best explanation: Bead sort is also known as gravity sort. It is because this algorithm was designed by keeping the NATURAL PHENOMENON of falling objects in MIND.
73.

What is the worst space complexity of bucket sort (k = number of buckets)?(a) O(n + k)(b) O(n.k)(c) O(n^2)(d) O(n log n)This question was addressed to me in an interview for internship.Query is from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (b) O(n.k)

The best I can EXPLAIN: Worst case space COMPLEXITY of bucket sort is O(n.k). So it is not an in place SORTING algorithm.

74.

Bucket sort is an in place sorting algorithm.(a) True(b) FalseThe question was asked by my college director while I was bunking the class.My question is taken from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Right OPTION is (b) False

Easy explanation - Bucket SORT is not an in place sorting algorithm. It requires an auxiliary SPACE of O(n k) in the worst CASE.

75.

Which of the following is not necessarily a stable sorting algorithm?(a) bucket sort(b) counting sort(c) merge sort(d) pigeonhole sortI got this question by my college director while I was bunking the class.This intriguing question originated from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (a) BUCKET sort

The explanation is: Bucket sort is not necessarily a stable sorting ALGORITHM. This is because its stability depends on the stability of the algorithm that we have USED to sort the individual BUCKETS.

76.

What is the best time complexity of bucket sort (k= number of buckets)?(a) O(n + k)(b) O(n.k)(c) O(n^2)(d) O(n log n)I had been asked this question during an online exam.This key question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (a) O(n + K)

The BEST explanation: Time complexity of bucket sort is O(n+k). It performs BETTER than any comparison BASED sort if there is a uniform input distribution.

77.

What is the worst case time complexity of bucket sort (k = number of buckets)?(a) O(n + k)(b) O(n.k)(c) O(n^2)(d) O(n log n)The question was posed to me in a job interview.I'd like to ask this question from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

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

For EXPLANATION: Time complexity of bucket sort is O(n^2) in the worst case. So if bucket sort does not GET the INPUTS in the DESIRED manner then it BECOMES very inefficient.

78.

Bucket sort is a generalization of which of the following sort?(a) LSD radix sort(b) Pigeonhole sort(c) Counting sort(d) MSD radix sortI had been asked this question during an interview for a job.My question is taken from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The CORRECT ANSWER is (b) Pigeonhole SORT

The best I can explain: Pigeonhole sort is a particular case of BUCKET sort. Bucket sort is also closely related to MSD RADIX sort.

79.

Bucket sort is most efficient in the case when __________(a) the input is non uniformly distributed(b) the input is uniformly distributed(c) the input is randomly distributed(d) the input range is largeThis question was addressed to me in a national level competition.The question is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct choice is (b) the INPUT is UNIFORMLY distributed

Easiest explanation - Bucket SORT works by distributing the array elements into a number of BUCKETS. So bucket sort is most EFFICIENT in the case when the input is uniformly distributed.

80.

Which of the following don’t affect the time complexity of bucket sort?(a) algorithm implemented for sorting individual buckets(b) number of buckets used(c) distribution of input(d) input valuesI had been asked this question during an online exam.This question is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Right choice is (d) input values

For explanation: Time complexity of bucket sort is affected by various FACTORS. These INCLUDE algorithm IMPLEMENTED for sorting individual buckets, number of buckets USED and distribution of input. It doesnot depend on the input VALUE. It can be either positive or negative or zero.

81.

Which of the following is not true about bucket sort?(a) It is a non comparison based integer sort(b) It is a distribution sort(c) It can also be considered as comparison based sort(d) It is in place sorting algorithmI have been asked this question in a job interview.Query is from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer» CORRECT answer is (d) It is in place SORTING algorithm

Easiest EXPLANATION - Bucket SORT is a non comparison based integer sort. It sorts the GIVEN data by distributing the array elements into a number of buckets. It is not an in place sorting technique.
82.

How many comparisons will be made to sort the array arr={1, 5, 3, 8, 2} using bucket sort?(a) 5(b) 7(c) 9(d) 0The question was asked in class test.This is a very interesting question from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

The CORRECT option is (d) 0

To explain: As bucket sort is an example of a non-comparison sort so it is ABLE to sort an array WITHOUT MAKING any comparison. So the ANSWER should be 0.

83.

What is the alternate name of bucket sort?(a) group sort(b) radix sort(c) bin sort(d) uniform sortI have been asked this question in an online interview.This question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (C) BIN sort

Explanation: BUCKET sort is also known as bin sort. It is an EXAMPLE of a non-comparison sort.

84.

Which of the following algorithm takes non linear time for sorting?(a) counting sort(b) quick sort(c) bucket sort(d) radix sortThe question was posed to me in a job interview.Query is from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

Right option is (b) quick sort

For explanation: Quick sort requires O(n log n) time for sorting so it TAKES non linear time for sorting whereas COUNTING sort, BUCKET sort and radix sort sorts in linear time.

85.

The complexity of which of the following sorting algorithms remains to be the same in its best, average and worst case?(a) quick sort(b) insertion sort(c) counting sort(d) gnome sortThe question was asked in an online interview.Origin of the question is Sorting in division Sorting of Data Structures & Algorithms II

Answer»

The correct option is (c) COUNTING SORT

The best I can EXPLAIN: The time complexity of counting sort remains unvaried in all the THREE cases. It is GIVEN by O(n+k).

86.

What is the average time complexity of counting sort?(a) O(n)(b) O(n+k) k=range of input(c) O(n^2)(d) O(n log n)This question was posed to me in an online interview.Origin of the question is Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (b) O(n+k) k=range of input

To explain: Time COMPLEXITY of counting SORT is O(n+k) as counting the occurrence of each element in the input range takes k time and then finding the correct index VALUE of each element in the sorted array takes n time.

87.

Which of the following uses the largest amount of auxiliary space for sorting?(a) Bubble sort(b) Counting sort(c) Quick sort(d) Heap sortThe question was asked in a national level competition.My question is based upon Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Right choice is (B) Counting sort

Best explanation: Counting sort REQUIRES auxiliary SPACE of O(n+k) whereas quick sort, bubble sort and heap sort are in PLACE sorting techniques. Thus counting sort requires most auxiliary space.

88.

Which of the following sorting techniques is stable?(a) quick sort(b) counting sort(c) heap sort(d) selection sortI have been asked this question in a national level competition.My doubt stems from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (b) COUNTING sort

For explanation: Counting sort is an example of stable SORTING algorithm as the elements with IDENTICAL values APPEAR in the same order in the output array as they were in the input array.

89.

It is not possible to implement counting sort when any of the input element has negative value.(a) True(b) FalseThe question was asked in an interview.This intriguing question originated from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

Right CHOICE is (b) False

The BEST I can explain: It is possible to extend the counting sort ALGORITHM for negative numbers as well. In such a case we store the minimum element at the 0th INDEX.

90.

What is the auxiliary space requirement of counting sort?(a) O(1)(b) O(n)(c) O(log n)(d) O(n+k) k=range of inputI had been asked this question in an international level competition.My question is from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (d) O(n+k) k=range of input

Easiest EXPLANATION - COUNTING SORT uses two EXTRA arrays to get the input array sorted. First array is REQUIRED to store the count of all the elements which fall in the range of input data elements, so its size is k. The second array is required to store the input elements in sorted manner, so its size is n. Thus overall auxiliary space required becomes O(n+k).

91.

Which of the following sorting techniques is most efficient if the range of input data is not significantly greater than a number of elements to be sorted?(a) selection sort(b) bubble sort(c) counting sort(d) insertion sortThe question was posed to me in an internship interview.This interesting question is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (c) counting sort

The BEST explanation: Time complexity of counting sort is given as O(N+K) where n is the number of input elements and k is the range of input. So if range of input is not significantly LARGER than number of elements in the array then it proves to be very efficient.

92.

Which of the following is not an example of non comparison sort?(a) bubble sort(b) counting sort(c) radix sort(d) bucket sortI have been asked this question in homework.The doubt is from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

The correct option is (a) bubble sort

Best EXPLANATION: Bubble sort is not an example of non comparison sort as it NEEDS to COMPARE array ELEMENTS in ORDER to sort an array.

93.

How many comparisons will be made to sort the array arr={1,5,3,8,2} using counting sort?(a) 5(b) 7(c) 9(d) 0This question was posed to me in an interview for internship.This question is from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Right answer is (d) 0

The BEST I can EXPLAIN: As counting sort is an example of non comparison sort so it is ABLE to sort an array WITHOUT making any comparison.

94.

What will be the order of elements of the array arr = {23, 67, 143, 654, 43} after first iteration of MSD sort is complete?(a) 23, 43, 67, 143, 654(b) 23, 67, 43, 143, 654(c) 23, 67, 143, 654, 43(d) 23, 143, 43, 654, 67I got this question in an online quiz.My question is based upon Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (b) 23, 67, 43, 143, 654

Easiest explanation - In the first ITERATION the array is sorted according to the most significant digit I.e. HUNDREDS place value. So the ORDER of elements will be 23, 67, 43, 143, 654.

95.

What is the advantage of radix sort over quick sort?(a) radix sort performs better than quick sort when we have log n bits for every digit(b) radix sort has lesser space complexity(c) radix sort is not a comparison based sorting technique(d) radix sort has better cache performance than quick sortThis question was posed to me by my college professor while I was bunking the class.This intriguing question comes from Sorting in section Sorting of Data Structures & Algorithms II

Answer» CORRECT option is (a) RADIX SORT performs better than QUICK sort when we have log n bits for every digit

Easy explanation - Radix sort performs better than quick sort when we have log n bits for every digit. But radix sort TAKES more space as compared to quick sort.
96.

Which of the following statement is not a stable sorting algorithm?(a) LSD radix sort(b) MSD radix sort(c) Counting sort(d) Pigeonhole sortThe question was asked at a job interview.This question is from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

Correct ANSWER is (b) MSD radix sort

Best EXPLANATION: MSD radix sort is not a stable sort. It is because the elements with identical values do not appear in the same order in the output ARRAY as they were in the input array.

97.

MSD radix sort is an in place sorting algorithm.(a) True(b) FalseThis question was addressed to me in an internship interview.The doubt is from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Right choice is (b) False

Easy EXPLANATION - MSD RADIX sort takes non CONSTANT TIME for sorting the input data. So it is not an in place sorting algorithm.

98.

What is the average time complexity of MSD radix sort (w= bits required to store each key)?(a) O(n + w)(b) O(n.w)(c) O(n^2)(d) O(n log n)The question was asked in semester exam.My query is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct choice is (B) O(n.w)

The best explanation: TIME COMPLEXITY of radix sort is O(n.w). It performs better than quick sort when we have LOG n BITS for every digit.

99.

MSD radix sort should be preferred over LSD radix sort when we have to maintain the original relative order.(a) True(b) FalseI had been asked this question in a job interview.My doubt is from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

Right choice is (B) False

The EXPLANATION is: MSD radix sort is not a stable sort WHEREAS LSD radix sort is stable. So when we REQUIRE to preserve the original order then in that case we should prefer LSD radix sort.

100.

Which of the following is not true about MSD radix sort?(a) its processing starts from the most significant digit(b) it is not a stable sort(c) it is an in place sorting algorithm(d) it is non comparison based sortI got this question in unit test.My doubt stems from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct choice is (c) it is an in place sorting ALGORITHM

The best EXPLANATION: MSD radix sort TAKES non constant time for sorting the input DATA. So it is not an in place sorting algorithm.