Engineering Questions with Answers - Multiple Choice Questions

Home » MCQs » Aeronautical Engineering » Linear Search Recursive Multiple Choice MCQ

# Linear Search Recursive Multiple Choice MCQ

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

**
View Answer**

Answer: c

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

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

**
View Answer**

Answer: a

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

What is the worst case runtime of linear search(recursive) algorithm?

a) O(n)

b) O(logn)

c) O(n^{2})

d) O(nx)

**
View Answer**

Answer: a

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

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

**
View Answer**

Answer: a

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

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

**
View Answer**

Answer: a

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.

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

**
View Answer**

Answer: a

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

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)

**
View Answer**

Answer: a

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

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

**
View Answer**

Answer: b

Explanation: Compare n with first element in arr[]. If element is found at first position, return it. Else recur for remaining array and n.

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

**
View Answer**

Answer: a

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

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

**
View Answer**

Answer: 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.