Data Structure Questions and Answers-Search an Element in an Array using Recursion

YOU CAN DOWNLOAD 200+ SUBJECTS PDF BOOK FOR COMPETITIVE EXAMINATIONS

CLICK HERE TO DOWNLOAD

Data Structure Questions and Answers-Search an Element in an Array using Recursion

Question 6 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Consider the following recursive implementation of linear search:

#include<stdio.h> int recursive....search....num(int *arr,  int num,  int idx,  int len) { if(idx == len) return -1; if(arr[idx] == num) return idx; return .....; } int main() { int arr[5] ={1, 3, 3, 3, 5}, num=2, len = 5; int indx = recursive....search....num(arr, num, 0, len); printf("Index of %d is %d", num, indx); return 0; }

Which of the following recursive calls should be added to complete the above code?

A
recursive....search....num(arr, num+1, id, x len);
B
recursive....search....num(arr, num, id, x len);
C
recursive....search....num(arr, num, idx+1, len);
D
recursive....search....num(arr, num+1, idx+1, len);
Question 6 Explanation: 
The recursive call "recursive....search....num(arr, num, idx+1, len)" should be added to complete the above code.

Question 7 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the output of the following code?

#include<stdio.h> int recursive....search....num(int *arr,  int num,  int idx,  int len) { if(idx == len) return -1; if(arr[idx] == num) return idx; return recursive....search....num(arr,  num,  idx+1,  len); } int main() { int arr[8] ={1, 2, 3, 3, 3, 5, 6, 7}, num=5, len = 8; int indx = recursive....search....num(arr, num, 0, len); printf("Index of %d is %d", num, indx); return 0; }
A
Index of 5 is 5
B
Index of 5 is 6
C
Index of 5 is 7
D
Index of 5 is 8
Question 7 Explanation: 
The program prints the index of 5, which is 5.

Question 8 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
How many times is the function recursive....search....num() called when the following code is executed?

#include<stdio.h> int recursive....search....num(int *arr,  int num,  int idx,  int len) { if(idx == len) return -1; if(arr[idx] == num) return idx; return recursive....search....num(arr,  num,  idx+1,  len); } int main() { int arr[8] ={1, 2, 3, 3, 3, 5, 6, 7}, num=5, len = 8; int indx = recursive....search....num(arr, num, 0, len); printf("Index of %d is %d", num, indx); return 0; }
A
5
B
6
C
7
D
8
Question 8 Explanation: 
The function recursive....search....num() is called 6 times when the above code is executed.

Question 9 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the time complexity of the above recursive implementation of linear search?
A
O(1)
B
O(n)
C
O(n2)
D
O(n3)
Question 9 Explanation: 
The time complexity of the above recursive implementation of linear search is O(n).

There are 9 questions to complete.