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

## Click on any option to know the CORRECT ANSWERS

 Question 1
Which of the following techniques can be used to search an element in an unsorted array?
 A Iterative linear search B Recursive binary search C Iterative binary search D All of the mentioned

Question 1 Explanation:
Iterative linear search can be used to search an element in an unsorted array.

Note: Binary search can be used only when the array is sorted.

 Question 2
Consider the array {1, 1, 1, 1, 1}:

Which of the following techniques can be used to search an element in the above array?

 A Iterative linear search B Recursive linear search C Recursive binary search D All of the mentioned

Question 2 Explanation:
All of the above mentioned techniques can be used to search an element in the above array.

 Question 3
What does the following code do?

#include<stdio.h> int search....num(int *arr,  int num,  int len) { int i; for(i = 0; i < len; i++) if(arr[i] == num) return i; return -1; } int main() { int arr ={1, 2, 3, 4, 5}, num=3, len = 5; int indx = search....num(arr, num, len); printf("Index of %d is %d", num, indx); return 0; }
 A Finds the index of all the occurrences of the number that is searched B Finds the index of the first occurrence of the number that is searched C Finds the index of the last occurrence of the number that is searched D None of the mentioned

Question 3 Explanation:
The code finds the index of the first occurrence of the number that is searched.

 Question 4
What is the output of the following code?

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