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.

Which of the following searching algorithm is fastest when the input array is sorted but has non uniformly distributed values?(a) jump search(b) linear search(c) binary search(d) interpolation searchA simple yet interesting question from data structure and algorithms.

Answer» CORRECT option is (C) binary search

Easy explanation - INTERPOLATION search has a time complexity of O(n) when the array does not have UNIFORMLY distributed values. So in such a CASE binary search has the least time complexity out of the given options.
2.

Interpolation search performs better than binary search when?(a) array has uniformly distributed values but is not sorted(b) array is sorted and has uniform distribution of values(c) array is sorted but the values are not uniformly distributed(d) array is not sortedThis is one of most asked question in data structure and algorithms interview.

Answer»

Right option is (B) ARRAY is sorted and has uniform distribution of values

For explanation: Interpolation search is an improvement over a binary search for the case when array is sorted and has uniformly DISTRIBUTED values. Binary search PERFORMS better when the values are not distributed uniformly.

3.

Rabin Karp algorithm and naive pattern searching algorithm have the same worst case time complexity.(a) true(b) falseI had been asked this question by my school principal while I was bunking the class.This is a very interesting question from Searching in portion Searching of Data Structures & Algorithms II

Answer» CORRECT answer is (a) true

Best explanation: The WORST case time complexity of Rabin Karp ALGORITHM is O(m*N) but it has a linear average case time complexity. So Rabin Karp and naive pattern searching algorithm have the same worst case time complexity.
4.

The naive pattern searching algorithm is an in place algorithm.(a) true(b) falseThe question was posed to me in examination.My question is based upon Searching in section Searching of Data Structures & Algorithms II

Answer»

The CORRECT answer is (a) true

Easiest explanation - The AUXILIARY SPACE complexity required by naive pattern searching algorithm is O(1). So it QUALIFIES as an in place algorithm.

5.

What is the auxiliary space complexity of Z algorithm for pattern searching (m = length of text, n = length of pattern)?(a) O(n + m)(b) O(m)(c) O(n)(d) O(m * n)I got this question in an online quiz.I'm obligated to ask this question of Searching topic in division Searching of Data Structures & Algorithms II

Answer»

Correct OPTION is (B) O(m)

Easy explanation - Z ALGORITHM is an efficient PATTERN searching algorithm as it searches the pattern in linear time. It an auxiliary space of O(m) for maintaining Z array.

6.

What is the time complexity of Z algorithm for pattern searching (m = length of text, n = length of pattern)?(a) O(n + m)(b) O(m)(c) O(n)(d) O(m * n)I had been asked this question in a job interview.My question is from Searching topic in portion Searching of Data Structures & Algorithms II

Answer»

Correct option is (a) O(N + m)

Explanation: Z algorithm is an efficient pattern SEARCHING algorithm as it searches the pattern in LINEAR time. It has a time COMPLEXITY of O(m + n) where m is the LENGTH of text and n is the length of the pattern.

7.

What is the worst case time complexity of KMP algorithm for pattern searching (m = length of text, n = length of pattern)?(a) O(n)(b) O(n*m)(c) O(m)(d) O(log n)I had been asked this question during an online exam.This interesting question is from Searching topic in section Searching of Data Structures & Algorithms II

Answer»

Correct CHOICE is (c) O(m)

The EXPLANATION is: KMP algorithm is an efficient pattern searching algorithm. It has a time complexity of O(m) where m is the LENGTH of text.

8.

Which of the following is a sub string of “SANFOUNDRY”?(a) SANO(b) FOUND(c) SAND(d) FONDThe question was posed to me in an online quiz.The doubt is from Searching topic in division Searching of Data Structures & Algorithms II

Answer»

Correct OPTION is (b) FOUND

Explanation: A sub string is a subset of another string. So “FOUND” is the only POSSIBLE sub string out of the given OPTIONS.

9.

What are the updated values of high and low in the array if the element being searched is lower than the value at calculated index in interpolation search? (pos = current position)(a) low = pos + 1, high remains unchanged(b) high = pos – 1, low remains unchanged(c) low = low +1, high = high – 1(d) low = pos +1, high = pos – 1I have been asked this question in an online interview.The above asked question is from Searching in chapter Searching of Data Structures & Algorithms II

Answer»

Correct choice is (b) high = pos – 1, LOW remains unchanged

For explanation: When the element being SEARCHED is lower than the value at the calculated position then in that CASE we update high and low remains unaltered. Updated value of high is high = pos – 1.

10.

What are the updated values of high and low in the array if the element being searched is greater than the value at calculated index in interpolation search? (pos = current position)(a) low = pos + 1, high remains unchanged(b) high = pos – 1, low remains unchanged(c) low = low +1, high = high – 1(d) low = pos +1, high = pos – 1I have been asked this question by my college director while I was bunking the class.This question is from Searching in portion Searching of Data Structures & Algorithms II

Answer» CORRECT answer is (a) low = pos + 1, HIGH REMAINS unchanged

The best I can explain: When the ELEMENT being searched is greater than the VALUE at the calculated position then in that case we update low and high remains unaltered. Updated value of low is low = pos + 1.
11.

Interpolation search has a better time complexity than exponential search for any given array.(a) True(b) FalseI had been asked this question at a job interview.I'm obligated to ask this question of Searching in division Searching of Data Structures & Algorithms II

Answer»

The correct choice is (B) False

For EXPLANATION: The worst CASE time complexity of interpolation search and exponential search are O(n) and O(log n) respectively. So exponential search is better when the worst case scenario is considered.

12.

Interpolation search is an in place algorithm.(a) true(b) falseThe question was asked in an internship interview.I need to ask this question from Searching in portion Searching of Data Structures & Algorithms II

Answer» RIGHT CHOICE is (a) true

The best EXPLANATION: INTERPOLATION search has an auxiliary space complexity of O(1). So it qualifies as an in place algorithm.
13.

Which of the following searching algorithm is fastest when the input array is not sorted but has uniformly distributed values?(a) jump search(b) linear search(c) binary search(d) interpolation searchThis question was posed to me by my college director while I was bunking the class.This intriguing question originated from Searching in chapter Searching of Data Structures & Algorithms II

Answer»

The correct OPTION is (B) linear search

Best explanation: Out of the given OPTIONS linear search is the only SEARCHING algorithm which can be applied to arrays which are not sorted. It has a time COMPLEXITY of O(n) in the worst case.

14.

Which of the following searching algorithm is fastest when the input array is sorted and has uniformly distributed values?(a) jump search(b) exponential search(c) binary search(d) interpolation searchThis question was addressed to me in an interview.Question is taken from Searching topic in division Searching of Data Structures & Algorithms II

Answer» RIGHT choice is (d) interpolation search

Easy explanation - Interpolation search has a time complexity of O( LOG log n) when the array is sorted and has uniformly distributed values. It has the LEAST time complexity out of the given options for such a CASE.
15.

What is the time complexity of exponential search when the input array is sorted but the values are not uniformly distributed?(a) O(n^1/2)(b) O(log log n)(c) O(n)(d) O(log n)The question was asked in semester exam.This key question is from Searching topic in portion Searching of Data Structures & Algorithms II

Answer»

The correct choice is (c) O(N)

To explain: When an array has NON uniformly distributed values then in that case the algorithm of INTERPOLATION search fails to work efficiently. As a RESULT, it has a time COMPLEXITY of O(n) in such a case.

16.

What is the auxiliary space requirement of interpolation search?(a) O(n)(b) O(2^n)(c) O(1)(d) O(log n)I had been asked this question during an online exam.This intriguing question originated from Searching topic in division Searching of Data Structures & Algorithms II

Answer»

Right CHOICE is (c) O(1)

Explanation: Interpolation SEARCH does not REQUIRE any auxiliary SPACE for finding the element being searched. So it has a CONSTANT auxiliary space O(1).

17.

What is the time complexity of interpolation search when the input array has uniformly distributed values and is sorted?(a) O(n)(b) O(log log n)(c) O(n log n)(d) O(log n)I had been asked this question in an international level competition.I'm obligated to ask this question of Searching topic in chapter Searching of Data Structures & Algorithms II

Answer»

The correct OPTION is (b) O(log log n)

Easy EXPLANATION - Interpolation search goes to different positions in the array depending on the value being SEARCHED. It is an improvement over binary search and has a TIME COMPLEXITY of O(log log n).

18.

In which of the following case jump search performs better than interpolation search?(a) When array has uniformly distributed values but is not sorted(b) when array is sorted and has uniform distribution of values(c) when array is sorted but the values increases exponentially(d) when array is not sortedI have been asked this question in homework.My question is based upon Searching in section Searching of Data Structures & Algorithms II

Answer»

Correct option is (c) when array is sorted but the values increases exponentially

The explanation is: In case of NON uniform distribution of values the time COMPLEXITY of INTERPOLATION search is O(n) whereas the average time complexity of jump search is O(n^1/2). So in such a case jump search has a better performance.

19.

Interpolation search is a variation of?(a) Linear search(b) Binary search(c) Jump search(d) Exponential searchThis question was posed to me during an online interview.My doubt stems from Searching topic in division Searching of Data Structures & Algorithms II

Answer»

The correct option is (B) Binary search

The best I can EXPLAIN: Interpolation search is a variation of binary search which gives the best RESULT when the array has uniformly distributed values. Interpolation search goes to DIFFERENT POSITIONS depending on the value being searched whereas binary search always goes to the middle element.

20.

Which of the following is the most desirable condition for interpolation search?(a) array should be sorted(b) array should not be sorted but the values should be uniformly distributed(c) array should have a less than 64 elements(d) array should be sorted and the values should be uniformly distributedThe question was asked in semester exam.My question comes from Searching in division Searching of Data Structures & Algorithms II

Answer»

Right answer is (d) ARRAY should be sorted and the VALUES should be uniformly distributed

The BEST I can explain: Desirable condition for INTERPOLATION search is that the array should be sorted and the values should be uniformly distributed. The ALGORITHM would fail to give the correct result if array is not sorted.

21.

Which of the following is not an alternate name of exponential search?(a) Logarithmic search(b) Doubling search(c) Galloping search(d) Struzik searchThis question was posed to me in an interview for job.My doubt is from Searching topic in section Searching of Data Structures & Algorithms II

Answer»

Correct option is (a) Logarithmic search

The EXPLANATION is: Logarithmic search is not an ALTERNATE NAME of the exponential search. Some alternate names of exponential search are DOUBLING search, Galloping search and Struzik search.

22.

Choose the incorrect statement about exponential search from the following.(a) Exponential search is an in place algorithm(b) Exponential search has a greater time complexity than binary search(c) Exponential search performs better than binary search when the element being searched is present near the starting point of the array(d) Jump search has a greater time complexity than an exponential searchThe question was posed to me in an interview for job.Asked question is from Searching in portion Searching of Data Structures & Algorithms II

Answer»

Right option is (b) Exponential search has a greater TIME complexity than BINARY search

Easiest explanation - Time complexity of exponential search and binary search are the same. But exponential search performs better than binary search when the element being SEARCHED is present near the starting point of the ARRAY.

23.

Exponential search performs better than binary search when the element being searched is present near the starting point of the array.(a) True(b) FalseThe question was posed to me by my college director while I was bunking the class.This intriguing question comes from Searching topic in portion Searching of Data Structures & Algorithms II

Answer»

Correct answer is (a) True

To EXPLAIN: EXPONENTIAL search first finds the range where binary search needs to be APPLIED. So when the ELEMENT is present NEAR the starting point of the array then exponential search performs better than standard binary search.

24.

What is the auxiliary space requirement of the exponential sort when used with recursive binary search?(a) O(n)(b) O(2^n)(c) O(1)(d) O(log n)I have been asked this question during a job interview.My question is from Searching topic in chapter Searching of Data Structures & Algorithms II

Answer»

The correct answer is (d) O(log n)

The BEST explanation: EXPONENTIAL search requires an auxiliary SPACE of log n when used with recursive binary search. This space is REQUIRED for the RECURSION call stack space.

25.

What is the auxiliary space requirement of an exponential sort when used with iterative binary search?(a) O(n)(b) O(2^n)(c) O(1)(d) O(log n)The question was asked in an online quiz.Enquiry is from Searching in portion Searching of Data Structures & Algorithms II

Answer»

Right CHOICE is (c) O(1)

BEST explanation: Exponential search does not require any AUXILIARY space for finding the ELEMENT being SEARCHED. So it has a constant auxiliary space O(1).

26.

Jump search has a worst case time complexity of O(n).(a) True(b) FalseThe question was asked during an interview.My question is taken from Searching in division Searching of Data Structures & Algorithms II

Answer»

Right option is (b) False

Easy EXPLANATION - The TIME complexity of jump SEARCH is O(n^1/2) in WORST and average case. It is due to the FACT that size of optimal jump is n^1/2.

27.

What is the auxiliary space requirement of the jump search?(a) O(n)(b) O(log n)(c) O(n^1/2)(d) O(1)I got this question during an interview.This interesting question is from Searching topic in division Searching of Data Structures & Algorithms II

Answer» RIGHT OPTION is (d) O(1)

Easy explanation - Jump SEARCH does not require any additional space for searching the required element. Thus its auxiliary space requirement will be O(1).
28.

What is the value of jump taken for maximum efficiency while implementing jump search?(a) n/2(b) n^2(c) n^1/2(d) log nI had been asked this question in a national level competition.I need to ask this question from Searching topic in chapter Searching of Data Structures & Algorithms II

Answer»

Correct choice is (C) n^1/2

For explanation: Total NUMBER of comparisons required will be n/k + k-1 in WORST case. This function will be minimum for k=n^1/2. So this value of jump will be the best for IMPLEMENTING jump search.

29.

What will be the maximum number of comparisons that can be made in jump search algorithm (assuming k to be blocks jumped)?(a) k(b) n/k(c) k-1(d) k-1This question was addressed to me in class test.Question is from Searching in division Searching of Data Structures & Algorithms II

Answer»

Right choice is (c) k-1

Explanation: Worst CASE occurs when the element being searched is present just after the element that has been COMPARED while MAKING the LAST jump. So, in this case k-1 COMPARISONS will have to be made.

30.

How many jumps will be made in the worst case of jump search(let block jumped =k)?(a) n*k(b) n/k(c) k/n(d) n+kThis question was posed to me by my school principal while I was bunking the class.Question is taken from Searching in chapter Searching of Data Structures & Algorithms II

Answer»

The CORRECT ANSWER is (b) n/k

The best EXPLANATION: WORST case occurs when the value to be searched is in the last section of the array. So, in this case the NUMBER of jumps will be n/k.

31.

Which of the following step is taken after finding an element having value greater than the element being searched?(a) linear search takes place in the forward direction(b) linear search takes place in the backward direction(c) binary search takes place in the forward direction(d) binary search takes place in a backward directionThe question was asked in an interview.This key question is from Searching in section Searching of Data Structures & Algorithms II

Answer»

Right ANSWER is (b) linear SEARCH takes place in the BACKWARD DIRECTION

Best explanation: First an element having value greater than the element being searched is found. After this linear search is performed in a backward direction.

32.

Jumps are made in the jump search algorithm until ___________(a) element having value less than that of the required element is found(b) element having value equal to the median of values of the array is found(c) element having value greater than that of the required element is found(d) middle element is found equal to the element being searchedThe question was asked by my school teacher while I was bunking the class.I'd like to ask this question from Searching topic in section Searching of Data Structures & Algorithms II

Answer»

Correct ANSWER is (c) element having value greater than that of the REQUIRED element is found

Easiest explanation - In jump search algorithm jumps are MADE until element having value greater than the value of element being searched is found. After this linear search is PERFORMED in backwards direction.

33.

Jump search algorithm requires which of the following condition to be true?(a) array should be sorted(b) array should have not be sorted(c) array should have a less than 64 elements(d) array should be partially sortedI got this question in my homework.I'd like to ask this question from Searching topic in chapter Searching of Data Structures & Algorithms II

Answer»

Correct ANSWER is (a) array should be sorted

Easiest explanation - JUMP sort REQUIRES the INPUT array to be sorted. The algorithm WOULD fail to give the correct result if array is not sorted.

34.

Which of the following false about Jump Search?(a) Jump Search is better than Linear Search(b) Useful when jumping back is more costly than jumping forward(c) Jump Search is worse than Binary Search(d) Jump search starts from the index 0 even though specified index is kI got this question in unit test.This key question is from Uniform Binary Search in chapter Searching of Data Structures & Algorithms II

Answer»

Correct OPTION is (d) Jump search starts from the index 0 even though specified index is k

Best explanation: Linear search has O(n) COMPLEXITY and Binary search has O(logn) complexity, in Jump search you have to jump backwards only once, HENCE it is preferable if jumping backwards is COSTLY. Jump search starts from index k (specified index) and SEARCHES for the element. It won’t start searching from index 0.

35.

How can Jump Search be improved?(a) Start searching from the end(b) Begin from the kth item, where k is the step size(c) Cannot be improved(d) Step size should be other than sqrt(n)This question was addressed to me in final exam.This intriguing question comes from Uniform Binary Search topic in portion Searching of Data Structures & Algorithms II

Answer»

Correct choice is (B) BEGIN from the kth item, where k is the step size

Explanation: This GIVES a very SLIGHT improvement as you are skipping the first k elements.

36.

What is the time complexity of binary search with iteration?(a) O(nlogn)(b) O(logn)(c) O(n)(d) O(n^2)This question was addressed to me in final exam.My query is from Binary Search Iterative topic in portion Searching of Data Structures & Algorithms II

Answer»

Correct choice is (B) O(LOGN)

The best explanation: T(n) = T(n/2) + THETA(1)

USING the divide and conquer MASTER theorem, we get the time complexity as O(logn).

37.

Given an array arr = {45,77,89,90,94,99,100} and key = 100; What are the mid values(corresponding array elements) generated in the first and second iterations?(a) 90 and 99(b) 90 and 100(c) 89 and 94(d) 94 and 99The question was posed to me in an online interview.The above asked question is from Binary Search Iterative topic in portion Searching of Data Structures & Algorithms II

Answer»

Correct ANSWER is (a) 90 and 99

Explanation: Trace the input with the binary search ITERATIVE code.

38.

Given an array arr = {5,6,77,88,99} and key = 88; How many iterations are done until the element is found?(a) 1(b) 3(c) 4(d) 2I had been asked this question during an interview.My question is taken from Binary Search Iterative in section Searching of Data Structures & Algorithms II

Answer» RIGHT OPTION is (d) 2

For explanation: Iteration1 : mid = 77; Iteration2 : mid = 88;
39.

What is the recurrence relation for the linear search recursive algorithm?(a) T(n-2)+c(b) 2T(n-1)+c(c) T(n-1)+c(d) T(n+1)+cI got this question in semester exam.Query is from Searching in portion Searching of Data Structures & Algorithms II

Answer»

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

Best explanation: After each call in the RECURSIVE algorithm, the SIZE of n is REDUCED by 1. Therefore the OPTIMAL solution is T(n-1)+c.

40.

Linear search(recursive) algorithm used in _____________(a) When the size of the dataset is low(b) When the size of the dataset is large(c) When the dataset is unordered(d) Never usedThe question was asked at a job interview.This intriguing question comes from Searching in section Searching of Data Structures & Algorithms II

Answer»

Correct CHOICE is (a) When the size of the dataset is low

The best EXPLANATION: It is USED when the size of the dataset is low as its runtime is O(n) which is more when compared to the binary search O(logn).

41.

What is the worst case runtime of linear search(recursive) algorithm?(a) O(n)(b) O(logn)(c) O(n^2)(d) O(nx)I had been asked this question at a job interview.The question is from Searching in portion Searching of Data Structures & Algorithms II

Answer»

Correct choice is (a) O(N)

Explanation: In the worst CASE scenario, there MIGHT be a need of CALLING the stack n TIMES. Therfore O(n).

42.

Is the space consumed by the linear search(recursive) and linear search(iterative) same?(a) No, recursive algorithm consumes more space(b) No, recursive algorithm consumes less space(c) Yes(d) Nothing can be saidI had been asked this question in an interview for job.The question is from Searching topic in section Searching of Data Structures & Algorithms II

Answer» CORRECT answer is (a) No, recursive algorithm CONSUMES more space

For explanation: The recursive algorithm consumes more space as it INVOLVES the USAGE the stack space(CALLS the function numerous times).
43.

Is there any difference in the speed of execution between linear serach(recursive) vs linear search(lterative)?(a) Both execute at same speed(b) Linear search(recursive) is faster(c) Linear search(Iterative) is faster(d) Cant be saidThis question was posed to me during an interview.I need to ask this question from Searching in section Searching of Data Structures & Algorithms II

Answer»

The correct choice is (c) Linear SEARCH(Iterative) is FASTER

The EXPLANATION is: The Iterative algorithm is faster than the latter as recursive algorithm has overheads like calling FUNCTION and REGISTERING stacks repeatedly.