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.

Matrix A is of order 3*4 and Matrix B is of order 4*5. How many elements will be there in a matrix A*B multiplied recursively.(a) 12(b) 15(c) 16(d) 20Answer know the answer? please give answer with explanation

Answer»

Correct choice is (B) 15

Best explanation: The RESULTANT matrix will be of order 3*5 when MULTIPLIED recursively and therefore the matrix will have 3*5=15 ELEMENTS.

2.

Under what case of Master’s theorem will the recurrence relation of binary search fall?(a) 1(b) 2(c) 3(d) It cannot be solved using master’s theoremThe question was asked in examination.My doubt stems from Masters theorem in section Recursion of Data Structures & Algorithms II

Answer»

Right answer is (b) 2

Best explanation: The recurrence relation of BINARY search is given by T(N) = T(n/2) + O(1). So we can OBSERVE that c = Logba so it will fall under case 2 of master’s theorem.

3.

What is the result of the recurrences which fall under the extended second case of Master’s theorem (let the recurrence be given by T(n)=aT(n/b)+f(n) and f(n)=n^c(log n)k?(a) T(n) = O(nlogba)(b) T(n) = O(n^c log n)(c) T(n)= O(n^c (log n)^k+1(d) T(n) = O(n^2)This question was posed to me in homework.This is a very interesting question from Masters theorem topic in division Recursion of Data Structures & Algorithms II

Answer» RIGHT option is (c) T(n)= O(n^c (log n)^k+1

The best EXPLANATION: In the extended second case of master’s THEOREM the necessary CONDITION is that c = logba. If this condition is true then T(n)= O(n^c(log n))^k+1.
4.

Which case of master’s theorem can be extended further?(a) 1(b) 2(c) 3(d) No case can be extendedI have been asked this question in an online interview.I'm obligated to ask this question of Masters theorem in chapter Recursion of Data Structures & Algorithms II

Answer»

Right ANSWER is (b) 2

To EXPLAIN: The SECOND CASE of master’s theorem can be extended for a case where f(n) = n^c (log n)^k and the resulting recurrence becomes T(n)= O(n^c (log n))^k+1.

5.

Under what case of Master’s theorem will the recurrence relation of stooge sort fall?(a) 1(b) 2(c) 3(d) It cannot be solved using master’s theoremThis question was addressed to me during an online interview.I'd like to ask this question from Masters theorem topic in portion Recursion of Data Structures & Algorithms II

Answer»

Correct choice is (a) 1

Easiest explanation - The recurrence relation of stooge SORT is given as T(n) = 3T(2/3n) + O(1). It is found too be EQUAL to O(n^2.7) using master’s theorem first case.

6.

Under what case of Master’s theorem will the recurrence relation of merge sort fall?(a) 1(b) 2(c) 3(d) It cannot be solved using master’s theoremI have been asked this question during an internship interview.Enquiry is from Masters theorem topic in chapter Recursion of Data Structures & Algorithms II

Answer»

The CORRECT option is (b) 2

Best EXPLANATION: The RECURRENCE relation of merge sort is given by T(n) = 2T(n/2) + O(n). So we can observe that c = Logba so it will FALL under CASE 2 of master’s theorem.

7.

What is the result of the recurrences which fall under third case of Master’s theorem (let the recurrence be given by T(n)=aT(n/b)+f(n) and f(n)=n^c?(a) T(n) = O(nlogba)(b) T(n) = O(n^c log n)(c) T(n) = O(f(n))(d) T(n) = O(n^2)This question was addressed to me in an interview.This question is from Masters theorem topic in section Recursion of Data Structures & Algorithms II

Answer»

Right option is (c) T(n) = O(f(n))

The best I can EXPLAIN: In third case of master’s theorem the necessary CONDITION is that c > logba. If this condition is true then T(n) = O(f(n)).

8.

We can solve any recurrence by using Master’s theorem.(a) true(b) falseThis question was posed to me in an international level competition.My question is based upon Masters theorem topic in section Recursion of Data Structures & Algorithms II

Answer» CORRECT choice is (b) false

Explanation: No we cannot solve all the RECURRENCES by only USING master’s THEOREM. We can solve only those which fall under the three cases PRESCRIBED in the theorem.
9.

What is the result of the recurrences which fall under second case of Master’s theorem (let the recurrence be given by T(n)=aT(n/b)+f(n) and f(n)=n^c?(a) T(n) = O(nlogba)(b) T(n) = O(n^c log n)(c) T(n) = O(f(n))(d) T(n) = O(n^2)I got this question by my college professor while I was bunking the class.Question is taken from Masters theorem topic in chapter Recursion of Data Structures & Algorithms II

Answer»

The correct choice is (B) T(N) = O(n^c LOG n)

To explain: In second case of master’s theorem the NECESSARY condition is that c = logba. If this condition is TRUE then T(n) = O(n^c log n)

10.

What is the result of the recurrences which fall under first case of Master’s theorem (let the recurrence be given by T(n)=aT(n/b)+f(n) and f(n)=n^c?(a) T(n) = O(n^logba)(b) T(n) = O(n^c log n)(c) T(n) = O(f(n))(d) T(n) = O(n^2)I got this question by my college professor while I was bunking the class.This key question is from Masters theorem in section Recursion of Data Structures & Algorithms II

Answer»

The correct choice is (a) T(N) = O(n^logba)

The best explanation: In FIRST case of master’s theorem the necessary CONDITION is that c < logba. If this condition is true then T(n) = O(n^logba).

11.

How many cases are there under Master’s theorem?(a) 2(b) 3(c) 4(d) 5The question was posed to me during an internship interview.My doubt is from Masters theorem topic in section Recursion of Data Structures & Algorithms II

Answer» CORRECT choice is (b) 3

To explain: There are primarily 3 cases under MASTER’s THEOREM. We can solve any RECURRENCE that falls under any one of these three cases.
12.

Master’s theorem is used for?(a) solving recurrences(b) solving iterative relations(c) analysing loops(d) calculating the time complexity of any codeI got this question in an internship interview.The above asked question is from Masters theorem topic in division Recursion of Data Structures & Algorithms II

Answer»

The correct answer is (a) SOLVING recurrences

Easy explanation - Master’s theorem is a DIRECT METHOD for solving recurrences. We can SOLVE any recurrence that falls under any one of the three cases of master’s theorem.

13.

Minimum time required to solve tower of hanoi puzzle with 4 disks assuming one move takes 2 seconds, will be __________(a) 15 seconds(b) 30 seconds(c) 16 seconds(d) 32 secondsThe question was asked by my college professor while I was bunking the class.Asked question is from Recursion in portion Recursion of Data Structures & Algorithms II

Answer» RIGHT answer is (B) 30 SECONDS

Easiest explanation - Number of moves = 2^4-1=16-1=15

Time for 1 MOVE = 2 seconds

Time for 15 moves = 15×2 = 30 seconds.
14.

Tower of hanoi problem can be solved iteratively.(a) True(b) FalseThis question was addressed to me by my school teacher while I was bunking the class.My question is from Recursion topic in portion Recursion of Data Structures & Algorithms II

Answer»

The correct choice is (a) True

For explanation: Iterative solution to tower of hanoi puzzle also EXISTS. Its APPROACH depends on whether the total numbers of DISKS are even or ODD.

15.

The time complexity of the solution tower of hanoi problem using recursion is _________(a) O(n^2)(b) O(2^n)(c) O(n log n)(d) O(n)I got this question at a job interview.The above asked question is from Recursion in division Recursion of Data Structures & Algorithms II

Answer»

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

The EXPLANATION is: TIME COMPLEXITY of the problem can be found out by solving the recurrence RELATION: T(n)=2T(n-1)+c. Result of this relation is found to be equal to 2^n. It can be solved using substitution.

16.

Which of the following is NOT a rule of tower of hanoi puzzle?(a) No disk should be placed over a smaller disk(b) Disk can only be moved if it is the uppermost disk of the stack(c) No disk should be placed over a larger disk(d) Only one disk can be moved at a timeThis question was addressed to me in an international level competition.My question is from Recursion topic in chapter Recursion of Data Structures & Algorithms II

Answer» RIGHT ANSWER is (c) No disk should be PLACED over a larger disk

For explanation: The RULE is to not put a disk over a SMALLER one. Putting a smaller disk over larger one is allowed.
17.

Which of the following methods can be used to search an element in a linked list?(a) Iterative linear search(b) Iterative binary search(c) Recursive binary search(d) Normal binary searchI got this question in an online quiz.The query is from Search an Element in a Linked List using Recursion topic in division Recursion of Data Structures & Algorithms II

Answer» CORRECT option is (a) Iterative linear search

To explain: Iterative linear search can be used to search an element in a LINKED list. Binary search can be used only when the list is SORTED.
18.

What is the objective of tower of hanoi puzzle?(a) To move all disks to some other rod by following rules(b) To divide the disks equally among the three rods by following rules(c) To move all disks to some other rod in random order(d) To divide the disks equally among three rods in random orderThis question was posed to me during a job interview.Question is taken from Recursion topic in chapter Recursion of Data Structures & Algorithms II

Answer» CORRECT answer is (a) To move all disks to some other rod by following rules

Explanation: OBJECTIVE of tower of hanoi problem is to move all disks to some other rod by following the following rules-1) Only one disk can be MOVED at a TIME. 2) Disk can only be moved if it is the uppermost disk of the stack. 3) No disk should be placed over a smaller disk.
19.

What will be time complexity when binary search is applied on a linked list?(a) O(1)(b) O(n)(c) O(n^2)(d) O(n^3)This question was posed to me in quiz.My doubt is from Search an Element in a Linked List using Recursion in section Recursion of Data Structures & Algorithms II

Answer»

Right option is (B) O(n)

EASY EXPLANATION - The time complexity will be O(n) when BINARY search is applied on a linked list.

20.

Can binary search be applied on a sorted linked list in O(Logn) time?(a) No(b) YesThe question was asked in an interview for job.This is a very interesting question from Search an Element in a Linked List using Recursion in division Recursion of Data Structures & Algorithms II

Answer»

Correct answer is (a) No

For EXPLANATION: Since linked list doesn’t ALLOW RANDOM access, binary search cannot be APPLIED on a sorted linked list in O(Logn) TIME.

21.

What is the time complexity of the above recursive implementation of binary search?(a) O(n)(b) O(2^n)(c) O(logn)(d) O(n!)I had been asked this question by my college professor while I was bunking the class.My question is from Search an Element in an Array using Recursion topic in chapter Recursion of Data Structures & Algorithms II

Answer»

Right ANSWER is (c) O(logn)

The best I can explain: The time COMPLEXITY of the above recursive IMPLEMENTATION of binary SEARCH is O(logn).

22.

Consider the array {1,1,1,1,1}. Select the wrong option?(a) Iterative linear search can be used to search for the elements in the given array(b) Recursive linear search can be used to search for the elements in the given array(c) Recursive binary search can be used to search for the elements in the given array(d) No method is defined to search for an element in the given arrayI have been asked this question in a job interview.This intriguing question comes from Search an Element in an Array using Recursion topic in section Recursion of Data Structures & Algorithms II

Answer»

Right CHOICE is (d) No method is defined to search for an ELEMENT in the given array

Easy EXPLANATION - ITERATIVE linear search, RECURSIVE linear search and Recursive binary search can be applied to search for an element in the above given array.

23.

Which of the following methods can be used to find the largest and smallest number in a linked list?(a) Recursion(b) Iteration(c) Both Recursion and iteration(d) Impossible to find the largest and smallest numbersThis question was posed to me during a job interview.This question is from Largest and Smallest Number in a Linked List using Recursion in chapter Recursion of Data Structures & Algorithms II

Answer» CORRECT choice is (c) Both Recursion and iteration

The BEST I can explain: Both recursion and iteration can be used to find the largest and SMALLEST NUMBER in a linked list.
24.

Which of the following techniques can be used to search an element in an unsorted array?(a) Iterative linear search(b) Recursive binary search(c) Iterative binary search(d) Normal binary searchThe question was posed to me by my school teacher while I was bunking the class.My question is based upon Search an Element in an Array using Recursion in chapter Recursion of Data Structures & Algorithms II

Answer»

The correct answer is (a) Iterative linear SEARCH

Explanation: Iterative linear search can be USED to search an ELEMENT in an unsorted ARRAY.

Note: Binary search can be used only when the array is SORTED.

25.

Which of the following methods can be used to find the largest and smallest element in an array?(a) Recursion(b) Iteration(c) Both recursion and iteration(d) No method is suitableThis question was addressed to me in examination.I would like to ask this question from Largest and Smallest Number in an Array using Recursion topic in portion Recursion of Data Structures & Algorithms II

Answer»

The correct answer is (C) Both recursion and ITERATION

The best I can explain: Both recursion and iteration can be used to FIND the largest and smallest element in an ARRAY.

26.

What will be the best case time complexity of recursive selection sort?(a) O(n)(b) O(n^2)(c) O(log n)(d) O(n log n)I have been asked this question in semester exam.Query is from Recursion topic in portion Recursion of Data Structures & Algorithms II

Answer»

Right choice is (B) O(n^2)

The BEST I can EXPLAIN: Selection sort’s algorithm is such that it finds the INDEX of minimum ELEMENT in each iteration even if the given array is already sorted. Thus its best case time complexity becomes O(n^2).

27.

Which of the following sorting algorithm is NOT stable?(a) Selection sort(b) Brick sort(c) Bubble sort(d) Merge sortThis question was posed to me during an interview.This key question is from Recursion topic in division Recursion of Data Structures & Algorithms II

Answer»

The correct answer is (a) Selection sort

Easiest explanation - Out of the GIVEN options selection sort is the only algorithm which is not stable. It is because the ORDER of identical elements in sorted output may be DIFFERENT from INPUT array.

28.

Is Coppersmith-Winograd algorithm better than Strassen’s algorithm in terms of time complexity?(a) True(b) FalseThis question was posed to me in my homework.The question is from Recursion topic in section Recursion of Data Structures & Algorithms II

Answer»

Correct option is (a) True

Explanation: Since The Coppersmith-Winograd algorithm multiplies the matrices in O(n^2.37) time. The time COMPLEXITY of RECURSIVE MULTIPLICATION of two square matrices by Strassen’s Method is found to be O(n^2.80). THEREFORE, Coppersmith-Winograd algorithm better than Strassen’s algorithm in terms of time complexity.

29.

Which of the following sorting algorithm has best case time complexity of O(n^2)?(a) bubble sort(b) selection sort(c) insertion sort(d) stupid sortThis question was posed to me in semester exam.This interesting question is from Recursion topic in section Recursion of Data Structures & Algorithms II

Answer»

Correct choice is (b) selection SORT

For explanation: Selection sort is not an adaptive sorting algorithm. It finds the index of MINIMUM element in each iteration even if the given array is already SORTED. THUS its best case time complexity becomes O(n^2).

30.

What will be the recurrence relation of the code of recursive selection 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 during an interview for a job.This key question is from Recursion topic in section Recursion of Data Structures & Algorithms II

Answer»

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

Explanation: Function to find the minimum element index takes n time.The RECURSIVE call is made to one less element than in the PREVIOUS call so the OVERALL recurrence relation becomes T(n) = T(n-1) + n.

31.

Which of the following is the biggest advantage of selection sort?(a) its has low time complexity(b) it has low space complexity(c) it is easy to implement(d) it requires only n swaps under any conditionThis question was posed to me in an online quiz.This key question is from Recursion topic in chapter Recursion of Data Structures & Algorithms II

Answer»

The correct option is (d) it requires only n swaps under any condition

For explanation: Selection SORT WORKS by obtaining least value ELEMENT in each iteration and then swapping it with the current index. So it will take n swaps under any condition which will be USEFUL when memory write operation is expensive.

32.

What is the time complexity of the fastest known matrix multiplication algorithm?(a) O(n^log7)(b) O(n^2.37)(c) O(n^3)(d) O(n!)This question was addressed to me during an interview.I need to ask this question from Recursion topic in division Recursion of Data Structures & Algorithms II

Answer»

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

To explain: The Coppersmith-Winograd ALGORITHM MULTIPLIES the MATRICES in O(n^2.37) time. Several IMPROVEMENTS have been MADE in the algorithm since 2010.

33.

If Matrix X is of order A*B and Matrix Y is of order C*D, and B=C then the order of the Matrix X*Y is A*D?(a) True(b) FalseThe question was asked in a national level competition.I need to ask this question from Recursion in division Recursion of Data Structures & Algorithms II

Answer»

Correct answer is (a) True

The EXPLANATION is: Given that B=C, so the two MATRIX can be RECURSIVELY multiplied. Therefore, the order of the Matrix X*Y is A*D.

34.

What is the time complexity of matrix multiplied recursively by Divide and Conquer Method?(a) O(n)(b) O(n^2)(c) O(n^3)(d) O(n!)I got this question by my school principal while I was bunking the class.This interesting question is from Recursion topic in section Recursion of Data Structures & Algorithms II

Answer»

Correct option is (c) O(n^3)

BEST explanation: The time COMPLEXITY of recursive multiplication of two square MATRICES by the Divide and Conquer method is found to be O(n^3) since there are total of 8 recursive calls.

35.

How many recursive calls are there in Recursive matrix multiplication by Strassen’s Method?(a) 5(b) 7(c) 8(d) 4The question was asked by my school teacher while I was bunking the class.Question is taken from Recursion topic in chapter Recursion of Data Structures & Algorithms II

Answer»

Correct choice is (B) 7

The best EXPLANATION: For the MULTIPLICATION two square matrix recursively using Strassen’s Method, there are 7 recursive calls performed for high TIME complexity.

36.

What is the time complexity of matrix multiplied recursively by Strassen’s Method?(a) O(n^log7)(b) O(n^2)(c) O(n^3)(d) O(n!)This question was posed to me during an online exam.This interesting question is from Recursion topic in division Recursion of Data Structures & Algorithms II

Answer»

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

The BEST I can EXPLAIN: The time COMPLEXITY of recursive multiplication of two square matrices by Strassen’s Method is found to be O(n^log7) SINCE there are TOTAL 7 recursive calls.

37.

If Matrix A is of order X*Y and Matrix B is of order M*N, then what is the order of the Matrix A*B given that Y=M?(a) Y*N(b) X*M(c) X*N(d) Y*MThe question was asked during an internship interview.The origin of the question is Recursion topic in section Recursion of Data Structures & Algorithms II

Answer» CORRECT answer is (c) X*N

The EXPLANATION is: The MATRIX A*B is of order X*N as it is GIVEN that Y=M i.e. NUMBER of columns in Matrix A is equal to total number of rows in matrix B. So the Matrix A*B must have X number of rows and N number of columns.
38.

What is the time complexity of the above recursive implementation used to reverse a string?(a) O(1)(b) O(n)(c) O(n^2)(d) O(n^3)The question was asked in an internship interview.This key question is from String Reversal using Recursion in section Recursion of Data Structures & Algorithms II

Answer» RIGHT CHOICE is (b) O(n)

For explanation: The time complexity of the above recursive implementation used to reverse a STRING is O(n).
39.

How many recursive calls are there in Recursive matrix multiplication through Simple Divide and Conquer Method?(a) 2(b) 6(c) 9(d) 8I had been asked this question in exam.Asked question is from Recursion in chapter Recursion of Data Structures & Algorithms II

Answer»

Correct choice is (d) 8

For explanation: For the multiplication two square matrix recursively USING Simple DIVIDE and Conquer METHOD, there are 8 recursive calls PERFORMED for high time complexity.

40.

In which of the following cases is the reversal of a string not equal to the original string?(a) Palindromic strings(b) Strings of length 1(c) Empty String(d) Strings of length 2The question was posed to me in unit test.This interesting question is from String Reversal using Recursion in portion Recursion of Data Structures & Algorithms II

Answer» RIGHT choice is (d) Strings of length 2

Best explanation: String “ab” is a string of length 2 whose REVERSAL is not the same as the GIVEN one. PALINDROMIC Strings, String of length 1 and EMPTY Strings case – the reversal is the same as the one given.
41.

Which of the following is the binary representation of 100?(a) 1010010(b) 1110000(c) 1100100(d) 1010101This question was posed to me during an interview.This intriguing question originated from Decimal to Binary Conversion using Recursion in division Recursion of Data Structures & Algorithms II

Answer»

The CORRECT option is (c) 1100100

For explanation: 100 = 64 + 32 + 4 = 2^6 + 2^5 + 2^2 = 1100100.

42.

What can be the minimum sum of digits for a 4 digit number?(a) 0(b) 1(c) 16(d) 36The question was asked in an interview for job.My doubt is from Sum of Digits of a Number using Recursion in section Recursion of Data Structures & Algorithms II

Answer»

The correct option is (b) 1

The BEST I can explain: The SUM of DIGITS will be minimum for the number 1000 and the sum is 1.

43.

What is the time complexity of the above code used to reverse a string?(a) O(1)(b) O(n)(c) O(n^2)(d) O(n^3)This question was addressed to me in examination.Question is taken from String Reversal using Recursion in portion Recursion of Data Structures & Algorithms II

Answer»

Correct choice is (b) O(N)

The best EXPLANATION: The time complexity of the above CODE used to reverse a STRING is O(n).

44.

What can be the maximum sum of digits for a 4 digit number?(a) 1(b) 16(c) 36(d) 26I have been asked this question by my college professor while I was bunking the class.The query is from Sum of Digits of a Number using Recursion topic in division Recursion of Data Structures & Algorithms II

Answer» CORRECT answer is (c) 36

The best I can explain: The sum of DIGITS will be MAXIMUM when all the digits are 9. Thus, the sum will be maximum for the NUMBER 9999, which is 36.
45.

Which of the following methods can be used to find the sum of digits of a number?(a) Recursion(b) Iteration(c) Greedy algorithm(d) Both recursion and iterationThis question was posed to me in final exam.My enquiry is from Sum of Digits of a Number using Recursion in chapter Recursion of Data Structures & Algorithms II

Answer» RIGHT answer is (d) Both RECURSION and iteration

For EXPLANATION: Both recursion and iteration can be used to FIND the sum of digits of a NUMBER.
46.

Which is the correct term of the given relation, lcm (a, b) * gcd (a, b) =?(a) |a*b|(b) a + b(c) a – b(d) a / bThe question was asked during an interview.This is a very interesting question from GCD LCM recursion topic in section Recursion of Data Structures & Algorithms II

Answer» CORRECT answer is (a) |a*B|

Explanation: The lcm is closely RELATED to GCD as lcm (a, b) * gcd (a, b) = |a*b|.
47.

Which algorithm is the most efficient numerical algorithm to obtain lcm?(a) Euler’s Algorithm(b) Euclid’s Algorithm(c) Chebyshev Function(d) Partial Division AlgorithmI had been asked this question in class test.Query is from GCD LCM recursion topic in division Recursion of Data Structures & Algorithms II

Answer»

Right option is (B) Euclid’s Algorithm

The best explanation: The most efficient way of calculating the LCM of a given number is using Euclid’s algorithm which computes the lcm in much lesser time COMPARED to other ALGORITHMS.

48.

What is the following expression, lcm (a, gcd (a, b)) equal to?(a) a(b) b(c) a*b(d) a + bI have been asked this question in an international level competition.This intriguing question originated from GCD LCM recursion in portion Recursion of Data Structures & Algorithms II

Answer»

The correct answer is (a) a

For explanation: Since the lcm FUNCTION FOLLOWS ABSORPTION laws so lcm (a, gcd (a, B)) equal to a.

49.

Is lcm an associative function.(a) True(b) FalseThis question was posed to me by my college director while I was bunking the class.This intriguing question originated from GCD LCM recursion in division Recursion of Data Structures & Algorithms II

Answer»

The correct choice is (a) True

Easy EXPLANATION - The LCM function is an associative function as lcm (a, lcm (B, c) is EQUAL to lcm (lcm (a, b), c).

50.

What is the following expression, lcm (a, lcm (b, c) equal to?(a) lcm (a, b, c)(b) a*b*c(c) a + b + c(d) lcm (lcm (a, b), c)I have been asked this question during an interview for a job.My query is from GCD LCM recursion in section Recursion of Data Structures & Algorithms II

Answer»

The correct answer is (d) lcm (lcm (a, b), c)

For EXPLANATION: SINCE LCM function follows ASSOCIATIVITY, HENCE lcm (a, lcm (b, c) is equal to lcm (lcm (a, b), c).