# Linear Search Recursive Multiple Choice Questions and Answers (MCQs)

This set of Data Structures & Algorithms Multiple Choice Questions & Answers (MCQs) focuses on “Linear Search Recursive”.

1. 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 said

Explanation: The Iterative algorithm is faster than the latter as recursive algorithm has overheads like calling function and registering stacks repeatedly.

2. 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 said

Explanation: The recursive algorithm consumes more space as it involves the usage the stack space(calls the function numerous times).

3. What is the worst case runtime of linear search(recursive) algorithm?
a) O(n)
b) O(logn)
c) O(n2)
d) O(nx)

Explanation: In the worst case scenario, there might be a need of calling the stack n times. Therfore O(n).

4. 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 used

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).

5. The array is as follows: 1,2,3,6,8,10. At what time the element 6 is found? (By using linear search(recursive) algorithm)
a) 4th call
b) 3rd call
c) 6th call
d) 5th call

Explanation: Provided that the search starts from the first element, the function calls itself till the element is found. In this case, the element is found in 4th call.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. The array is as follows: 1,2,3,6,8,10. Given that the number 17 is to be searched. At which call it tells that there’s no such element? (By using linear search(recursive) algorithm)
a) 7th call
b) 9th call
c) 17th call
d) The function calls itself infinite number of times

Explanation: The function calls itself till the element is found. But at the 7th call it terminates as goes outside the array.

7. What is the best case runtime of linear search(recursive) algorithm on an ordered set of elements?
a) O(1)
b) O(n)
c) O(logn)
d) O(nx)

Explanation: The best case occurs when the given element to be found is at the first position. Therefore O(1) is the correct answer.

8. Which of the following code snippet performs linear search recursively?
a)

for(i=0;i<n;i++)
{
if(a[i]==key)
printf("element found");
}

b)

LinearSearch(int[] a, n,key)
{
if(n<1)
return False
if(a[n]==key)
return True
else
LinearSearch(a,n-1,key)
}

c)

LinearSearch(int[] a, n,key)
{
if(n<1)
return True
if(a[n]==key)
return False
else
LinearSearch(a,n-1,key)
}

d)

LinearSearch(int[] a, n,key)
{
if(n<1)
return False
if(a[n]==key)
return True
else
LinearSearch(a,n+1,key)
}
Explanation: Compare n with first element in arr[]. If element is found at first position, return it. Else recur for remaining array and n.

9. Can linear search recursive algorithm and binary search recursive algorithm be performed on an unordered list?
a) Binary search can’t be used
b) Linear search can’t be used
c) Both cannot be used
d) Both can be used

Explanation: As binary search requires comparison, it is required that the list be ordered. Whereas this doesn’t matter for linear search.

10. 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)+c

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.

Sanfoundry Global Education & Learning Series – Data Structures & Algorithms.

To practice all areas of Data Structures & Algorithms, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]