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.

1.

What is the basic principle in Rabin Karp algorithm?(a) Hashing(b) Sorting(c) Augmenting(d) Dynamic ProgrammingPlease answer the question asap those who know Rabin Karp algorithm.

Answer»

Right option is (a) Hashing

Easy explanation - The basic PRINCIPLE employed in RABIN Karp algorithm is hashing. In the GIVEN text EVERY substring is converted to a hash value and compared with the hash value of the PATTERN.

2.

What is the worst case time complexity of tree sort (when implemented with a balanced tree)?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)

Answer»

Correct answer is (b) O(n LOG n)

Easiest explanation - The worst case TIME complexity of tree sort DEPENDS on whether the tree used in the implementation is balanced or not. If the tree is balanced then the worst case complexity is O(n log n).

3.

Which of the following is a variant of insertion sort?(a) selection sort(b) shell sort(c) odd-even sort(d) stupid sortPlease answer.

Answer»

The correct OPTION is (b) shell sort

Explanation: Shell sort is a variation of insertion sort. It has a BETTER RUNNING time in practical APPLICATIONS.

4.

Which of the following non-comparison sort can also be considered as a comparison based sort?(a) counting sort(b) MSD radix sot(c) bucket sort(d) pigeonhole sortPlease answer this question of dsa.

Answer»

The correct ANSWER is (c) bucket sort

Easiest EXPLANATION - Bucket sort can also be CONSIDERED as a comparison BASED sort. It is because it can also be implemented with comparisons.

5.

Which of the following is not true about radix sort?(a) Radix sort performs better than quick sort when we have log n bits for every digit(b) Radix sort has better cache performance than quick sort(c) Radix sort has higher values of constant factor in asymptotic notation(d) Radix sort takes more space than quick sortRadix sort people please answer.

Answer»

Correct OPTION is (B) Radix sort has better cache performance than quick sort

To explain: Quick sort has a better cache performance than radix sort. Radix sort also takes more SPACE as COMPARED to quick sort.

6.

Which of the following sorting algorithm is not a constituent of introsort?(a) selection sort(b) quicksort(c) insertion sort(d) heap sortintrosort knowledgeable people please answer.

Answer» RIGHT answer is (a) selection sort

Explanation: Introsort is a HYBRID sorting algorithm which means it USES more than one sorting algorithm as a routine. It may use quick sort or heap sort or INSERTION sort depending on the given situation.
7.

Shell sort is also known as _____________(a) diminishing decrement sort(b) diminishing increment sort(c) partition exchange sort(d) diminishing insertion sortA very nice question close to me from dsa.

Answer»

Right OPTION is (b) DIMINISHING increment sort

Easiest explanation - Shell sort is also known as diminishing increment sort since each pass is defined by an increment H such that only the records which are h units APART will be sorted.

8.

Which of the following is not an advantage of tree sort?(a) it has a low space complexity(b) it has good time complexity for balanced BST(c) it is an online sorting algorithm(d) it is stable sorting algorithmI got this question in an online quiz.Question is taken from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (a) it has a low SPACE complexity

To explain: Tree sort has a linear time complexity O(n) which makes it inefficient. This the MAIN reason why sorting ALGORITHMS LIKE quick sort, HEAP sort etc. are preferred over it.

9.

The worst case time complexity of tree sort remains unaffected when implemented with an unbalanced tree or a balanced tree.(a) True(b) FalseThe question was posed to me during an interview.This interesting question is from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The correct CHOICE is (b) False

The explanation is: The time complexity of tree SORT is AFFECTED when implemented with an unbalanced tree or a balanced tree. In case of a balanced tree it is O(n LOG n) and in case of unbalanced tree it is O(n^2).

10.

Which of the following version of tree sort will have the highest worst case time complexity?(a) using AVL tree as BST(b) using red black tree as BST(c) using splay tree as BST(d) using ordinary BSTThis question was addressed to me in exam.My question is based upon Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

Right answer is (d) using ordinary BST

Explanation: Out of the given options TREE SORT has the highest worst CASE TIME complexity with ordinary BST as it may not be balanced in every case. Whereas all other options have SELF balancing BST.

11.

Which of the following sorting algorithm is not in place?(a) insertion sort(b) quick sort(c) tree sort(d) gnome sortI got this question in an online quiz.I want to ask this question from Sorting topic in portion Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (c) TREE sort

The BEST I can explain: Out of the given options tree sort is the only ALGORITHM which is not in place. It is because the auxiliary SPACE required by tree sort is O(n).

12.

Which of the following is not true about tree sort?(a) it is not an in place sorting algorithm(b) its every implementation is adaptive(c) it requires in order traversal of BST for sorting input elements(d) it is a stable sortI got this question in an interview.Origin of the question is Sorting topic in section Sorting of Data Structures & Algorithms II

Answer» RIGHT answer is (B) its every implementation is adaptive

For explanation: Every implementation of tree sort is not adaptive. It BECOMES adaptive only when IMPLEMENTED with a splay tree as BST.
13.

In which of the following case does a tree sort become adaptive?(a) when implemented with an unbalanced tree(b) when implemented with a balanced tree(c) when implemented with a splay tree as BST(d) when implemented with AVL tree as BSTI have been asked this question in examination.The origin of the question is Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (c) when implemented with a splay tree as BST

The best explanation: Tree SORT BECOMES an adaptive sort when it is implemented with a splay tree as a BST. In such a case the best case TIME complexity is better than (N LOG n).

14.

What is the worst case time complexity of tree sort (when implemented with an unbalanced tree)?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)I got this question in an internship interview.The query is from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

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

For explanation: The worst CASE time COMPLEXITY of TREE sort depends on whether the tree USED in the implementation is balanced or not. If the tree is unbalanced then the worst case complexity is O(n^2).

15.

What is the auxiliary space complexity of tree sort?(a) O(1)(b) O(n)(c) O(log n)(d) O(n log n)This question was posed to me in an internship interview.My query is from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (b) O(N)

The best I can explain: TREE sort requires auxiliary SPACE for maintaining a binary search tree. So the auxiliary space COMPLEXITY of tree sort is O(n).

16.

What is the best case time complexity of tree sort?(a) O(n)(b) O(n log n)(c) O(n^2)(d) O(log n)I had been asked this question in an online quiz.My doubt is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer» RIGHT ANSWER is (B) O(n log n)

For EXPLANATION: The BEST case time complexity of tree sort is the same as its average case complexity. So best case time complexity is O(n log n).
17.

What is the average case time complexity of tree 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.I'd like to ask this question from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

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

Best EXPLANATION: As on an average every element takes log n time for insertion in a binary SEARCH tree so for n elements O(n log n) time will be REQUIRED on an average.

18.

Which of the following is a comparison based sort?(a) tree sort(b) radix sort(c) counting sort(d) pigeonhole sortI got this question during an interview.This key question is from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Correct ANSWER is (a) tree SORT

The explanation is: In tree sort, we need to compare elements as we insert them in the binary search tree. THUS it QUALIFIES as a comparison BASED sort.

19.

Which of the following sorting algorithm uses a binary search tree?(a) radix sort(b) tree sort(c) odd-even sort(d) bead sortThis question was posed to me in exam.The above asked question is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Right answer is (b) tree SORT

The BEST explanation: Tree sort makes use of a BINARY search tree. It is because every time when a BST is traversed in an in order fashion it gives a sorted output.

20.

Which of the following sorting algorithm is stable?(a) Selection sort(b) Quick sort(c) Tree sort(d) Heap sortI had been asked this question in semester exam.I'd like to ask this question from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Right answer is (C) Tree sort

For explanation: Out of the given OPTIONS Tree 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.

21.

Which of the following traversal in a binary search tree results in a sorted output?(a) in order traversal(b) pre order traversal(c) post order traversal(d) breadth first traversalThis question was posed to me in semester exam.My doubt stems from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

The CORRECT choice is (a) in ORDER traversal

The best I can EXPLAIN: Tree sort uses a binary search tree for sorting the given elements. FIRST a BST is formed by using the input data elements and then the BST is traversed in an in order FASHION which gives a sorted output.

22.

Tree sort is an online sorting algorithm.(a) True(b) FalseI got this question during an online interview.This intriguing question originated from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (a) True

Easiest EXPLANATION - Tree 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.

23.

Which of the following data structure is required for the implementation of tree sort?(a) any ordinary tree(b) balanced tree(c) binary search tree(d) unbalanced treeThe question was asked in examination.Question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct ANSWER is (c) binary search TREE

To EXPLAIN: Tree sort uses a binary search tree for sorting the given ELEMENTS. Tree sort can also be performed by using an unbalanced binary search tree.

24.

What will be the recurrence relation of the code of recursive insertion sort?(a) T(n) = 2T(n/2) + n(b) T(n) = 2T(n/2) + c(c) T(n) = T(n-1) + n(d) T(n) = T(n-1) + cThe question was asked in an interview for job.The origin of the question is Sorting in section Sorting of Data Structures & Algorithms II

Answer» RIGHT ANSWER is (c) T(n) = T(n-1) + n

Easy explanation - The recurrence relation of the CODE of recursive insertion sort is T(n) = T(n-1) + n. It can be solved by the method of substitution and is found to be EQUAL to n^2.
25.

Which of the following sorting algorithm is stable?(a) Selection sort(b) Quick sort(c) Insertion sort(d) Heap sortThe question was posed to me in an online quiz.The origin of the question is Sorting in section Sorting of Data Structures & Algorithms II

Answer» RIGHT choice is (c) Insertion sort

Best explanation: Out of the GIVEN options insertion 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.
26.

Insertion sort is an online sorting algorithm.(a) true(b) falseThe question was posed to me at a job interview.I want to ask this question from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

The correct option is (a) true

Easiest explanation - Insertion sort does not require the entire INPUT DATA in 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.

27.

Which of the following is an advantage of recursive insertion sort over its iterative version?(a) it has better time complexity(b) it has better space complexity(c) it is easy to implement(d) it has no significant advantageThis question was posed to me in examination.This interesting question is from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (d) it has no significant advantage

The best I can EXPLAIN: Recursive INSERTION sort has no significant advantage over ITERATIVE insertion sort. It is just a different WAY to IMPLEMENT the same.

28.

Which of the following sorting algorithm uses a binary search?(a) radix sort(b) binary insertion sort(c) odd-even sort(d) bead sortI had been asked this question during an internship interview.I need to ask this question from Sorting in chapter Sorting of Data Structures & Algorithms II

Answer» CORRECT answer is (b) binary insertion sort

Best explanation: Binary insertion 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.
29.

Which of the following sorting algorithm is stable?(a) Selection sort(b) Quick sort(c) Binary insertion sort(d) Heap 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 portion Sorting of Data Structures & Algorithms II

Answer» RIGHT OPTION is (c) Binary INSERTION sort

The best EXPLANATION: Out of the given options binary insertion 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.
30.

How many comparisons will be made in the worst case when an array of size n will be sorted by using a binary insertion sort algorithm?(a) n(b) 1(c) log n(d) n log nThis question was addressed to me in an interview for job.My question is based upon Sorting in section Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (c) log N

The best explanation: Binary insertion sort makes log n comparisons in the WORST case. WHEREAS the STANDARD VERSION makes n comparisons in the worst case.

31.

Binary Insertion sort is an online sorting algorithm.(a) True(b) FalseI have been asked this question during an interview.My question is based upon Sorting in chapter Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (a) True

Easy explanation - Binary INSERTION 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.

32.

Which of the following is an advantage of binary insertion sort over its standard version?(a) it has better time complexity(b) it has better space complexity(c) it makes less number of comparisons(d) it has no significant advantageI got this question in examination.This key question is from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

The correct option is (C) it makes less NUMBER of COMPARISONS

Easy EXPLANATION - Binary insertion sort makes less number of comparisons as compared to the standard version of insertion sort. Binary insertion sort makes log n comparisons in the worst case as compared to n comparisons made in the standard version.

33.

Which of the following is a variation of bubble sort?(a) selection sort(b) odd even sort(c) cocktail sort(d) stupid sortI had been asked this question in semester exam.Query is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer» RIGHT choice is (b) ODD even sort

The BEST explanation: Odd even sort is a variation of bubble sort. But unlike bubble sort, odd even sort traverses the array in TWO phases- odd phase and even phase.
34.

Which of the following sorting algorithm is stable?(a) Selection sort(b) Quick sort(c) Bubble sort(d) Heap sortThe question was asked in an interview.My question is taken from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Right choice is (c) Bubble sort

The best EXPLANATION: Out of the given options bubble 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.

35.

What will be the recurrence relation of the code of recursive bubble sort?(a) T(n) = 2T(n/2) + n(b) T(n) = 2T(n/2) + c(c) T(n) = T(n-1) + n(d) T(n) = T(n-1) + cI have been asked this question in an interview.Question is taken from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

Right answer is (c) T(n) = T(n-1) + n

The best EXPLANATION: The recurrence RELATION of the code of recursive bubble sort is T(n) = T(n-1) + n. It can be solved by the method of SUBSTITUTION and is FOUND to be equal to n^2.

36.

Bubble sort is also known as ___________(a) stupid sort(b) ship sort(c) sinking sort(d) shell sortThis question was posed to me in examination.My question is based upon Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The CORRECT choice is (c) sinking sort

The best explanation: Bubble sort is also referred to as sinking sort. It CONTINUOUSLY compares the VALUE of adjacent elements as it traverses through an ARRAY and swaps the elements which are out of order.

37.

Which of the following is an advantage of recursive bubble sort over its iterative version?(a) it has better time complexity(b) it has better space complexity(c) it is easy to implement(d) it has no significant advantageThe question was asked by my college director while I was bunking the class.This intriguing question comes from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

The CORRECT ANSWER is (d) it has no significant advantage

For explanation: RECURSIVE bubble sort has no significant advantage over ITERATIVE bubble sort. It is just a different WAY to implement the same.

38.

What is the worst case time complexity of permutation sort?(a) O(n^2)(b) O(n*n!)(c) O(infinity)(d) O(n log n)I had been asked this question in final exam.This interesting question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Right answer is (c) O(INFINITY)

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

39.

What is the best case time complexity of permutation sort?(a) O(n^2)(b) O(n)(c) O(n log n)(d) O(1)I had been asked this question in exam.This intriguing question originated from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The correct answer is (B) O(n)

EASY explanation - Best case time complexity of permutation sort 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.

40.

What is the auxiliary space requirement of permutation sort?(a) O(n)(b) O(1)(c) O(log n)(d) O(n log n)The question was asked in a job interview.I would like to ask this question from Sorting topic in chapter Sorting of Data Structures & Algorithms II

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

Best explanation: PERMUTATION sort algorithm does not require any extra space for sorting the input array. THUS its auxiliary space requirement is O(1).
41.

Permutation sort 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 arrayThis question was posed to me in final exam.This intriguing question comes from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

The CORRECT answer is (a) generating random permutations of its INPUT

To explain: Permutation sort algorithm successively GENERATES permutations of its input. This process is repeated until the SORTED VERSION of the array is found.

42.

Which of the following is not an alternative name of permutation sort?(a) stupid sort(b) bogo sort(c) donkey sort(d) monkey sortThis question was addressed to me in an interview for job.I would like to ask this question from Sorting topic in chapter Sorting of Data Structures & Algorithms II

Answer»

Correct option is (c) DONKEY SORT

The best I can explain: Permutation sort is also known by names like stupid sort, MONKEY sort, BOGO sort, SLOW sort and shotgun sort. These names are particularly chosen due to its inefficient algorithm.

43.

What is the average time complexity of stooge sort?(a) O(n^2)(b) O(n^3)(c) O(n^2.6)(d) O(n^2.7)The question was posed to me during an internship interview.I'd like to ask this question from Sorting in division Sorting of Data Structures & Algorithms II

Answer»

The CORRECT answer is (d) O(n^2.7)

Easiest explanation - The recurrence relation of stooge sort is given as T(n) = 3T(2/3n) + O(1). It is found to be equal to O(n^2.7) USING the master’s THEOREM.

44.

Stooge sort is a stable sorting algorithm.(a) true(b) falseThis question was addressed to me in unit test.This question is from Sorting in portion Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (b) false

Easy explanation - Stooge sort is not a stable SORTING algorithm. 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.

45.

Stooge sort is a comparison based sorting algorithm.(a) true(b) falseI got this question in an interview for job.My doubt stems from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (a) true

Easiest explanation - Stooge 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.

46.

What is the first step in the algorithm of stooge sort(after base case)?(a) apply stooge sort on first 2/3 elements of array(b) apply stooge sort on last 2/3 elements of array(c) apply stooge sort on first 1/3 elements of array(d) compare first and last element of the arrayThis question was addressed to me in a job interview.I need to ask this question from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (d) compare FIRST and last element of the array

Easy explanation - The first step in the algorithm of STOOGE SORT is to compare the first and last element of the array and SWITCH them if found out of order. In the second step stooge sort is APPLIED on the first 2/3 elements of the array.

47.

What is the space complexity of stooge sort?(a) O(n)(b) O(1)(c) O(log n)(d) O(n log n)The question was posed to me in an internship interview.My question is from Sorting topic in chapter Sorting of Data Structures & Algorithms II

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

The best I can EXPLAIN: The space COMPLEXITY of the stooge SORT is O(n). It is used to store the input array.
48.

In which of the following case stooge sort is most efficient (in terms of time complexity)?(a) when input array is already sorted(b) when input array is reverse sorted(c) when input array is large(d) it has the same time complexity in any caseI have been asked this question in homework.Origin of the question is Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (d) it has the same time complexity in any CASE

For explanation: Stooge SORT has the same time complexity under any case. It is given by the recurrence relation T(n) = 3T(2/3n) + O(1).

49.

What is the recurrence relation for stooge sort?(a) T(n) = 2T(2/3n) + O(n)(b) T(n) = 2T(2/3n) + O(1)(c) T(n) = 3T(2/3n) + O(n)(d) T(n) = 3T(2/3n) + O(1)The question was posed to me in an international level competition.The question is from Sorting topic in division Sorting of Data Structures & Algorithms II

Answer»

Correct answer is (d) T(n) = 3T(2/3n) + O(1)

The best explanation: In stooge sort recursion is applied to 2/3 part of the ARRAY 3 TIMES. Rest of the PORTION of code has a constant time complexity. So the overall recurrence relation becomes T(n) = 3T(2/3n) + O(1).

50.

Which one of the following sorting algorithm requires recursion?(a) odd even sort(b) stooge sort(c) selection sort(d) counting sortThe question was asked in exam.The question is from Sorting in section Sorting of Data Structures & Algorithms II

Answer»

The CORRECT answer is (b) stooge sort

To explain: Stooge 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.