/* */ Click to Join Live Class with Shankar sir Call 9798158723

Data Structure MCQ - Linear Search

Q1.Is there any difference in the speed of execution between linear serach(recursive) vs linear search(lterative)?
1. Both execute at same speed
2. Linear search(recursive) is faster
3. Linear search(Iterative) is faster
4. Cant be said

Explanations :The Iterative algorithm is faster than the latter as recursive algorithm has overheads like calling function and registering stacks repeatedly.
Q2. Is there any difference in the speed of execution between linear serach(recursive) vs linear search(lterative)?
1. Both execute at same speed
2. Linear search(recursive) is faster
3. Linear search(Iterative) is faster
4. Cant be said

Explanations :The Iterative algorithm is faster than the latter as recursive algorithm has overheads like calling function and registering stacks repeatedly.
Q3.What is the output of following program?
```#include

void print(int n, int j)
{
if (j >= n)
return;
if (n-j > 0 && n-j >= j)
printf("%d %dn", j, n-j);
print(n, j+1);
}

int main()
{
int n = 8;
print(n, 1);
}```
1. 1 7
2 6
3 5
4 4
4 4
2. 1 7
2 6
3 5
4 4
3. 1 7
2 6
3 5
4. 1 2
3 4
5 6
7 8

Explanations :For a given number n, the program prints all distinct pairs of positive integers with sum equal to n.
Q4.For a given number n, the program prints all distinct pairs of positive integers with sum equal to n.
1. 14
2. 2
3. 6
4. 3

Q5.What is the worst case for linear search?
1. O(nlogn)
2. O(logn)
3. O(n)
4. O(1)

Explanations : Worst case is when the desired element is at the tail of the array or not present at all, in this case you have to traverse till the end of the array, hence the complexity is O(n).
Q6.Is the space consumed by the linear search(recursive) and linear search(iterative) same?
1. No, recursive algorithm consumes more space
2. No, recursive algorithm consumes less space
3. yes
4. Nothing can be said

Explanations :The recursive algorithm consumes more space as it involves the usage the stack space(calls the function numerous times).
Q7.Linear search(recursive) algorithm used in _____________
1. When the size of the dataset is low
2. When the size of the dataset is large
3. When the dataset is unordered
4. Never used

Explanations :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).
Q8.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)
1. 4th call
2. 3th call
3. 6th call
4. 5th call

Explanations :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.
Q9.Given a sorted array of integers, what can be the minimum worst case time complexity to find ceiling of a number x in given array? Ceiling of an element x is the smallest element present in array which is greater than or equal to x. Ceiling is not present if x is greater than the maximum element present in array. For example, if the given array is {12, 67, 90, 100, 300, 399} and x = 95, then output should be 100.
1. O(LogLogn)
2. O(n)
3. O(Logn)
4. O(Logn * Logn)