# Data Structure Questions and Answers-Linear Search Iterative

## Data Structure Questions and Answers-Linear Search Iterative

 Question 1
Where is linear searching used?
 A When the list has only a few elements B When performing a single search in an unordered list C Used all the time D When the list has only a few elements and When performing a single search in an unordered list
Question 1 Explanation:
It is practical to implement linear search in the situations mentioned in When the list has only a few elements and When performing a single search in an unordered list, but for larger elements the complexity becomes larger and it makes sense to sort the list and employ binary search or hashing.

 Question 2
Select the code snippet which performs unordered linear search iteratively?

int unorderedLinearSearch(int arr[], int size, int data) { int index; for(int i = 0; i < size; i++) { if(arrint unorderedLinearSearch(int arr[], int size, int data) { int index; for(int i = 0; i < size; i++) { if(arr

int unorderedLinearSearch(int arr[], int size, int data) { int index; for(int i = 0; i <= size; i++) { if(arrNTA NET Questions answers Question 2 Explanation:   Unordered term refers to the given array, that is, the elements need not be ordered. To search for an element in such an array, we need to loop through the elements until the desired element is found.
 Question 3
What is the best case for linear search?
 A O(nlogn) B O(logn) C O(n) D O(1)
Question 3 Explanation:
The element is at the head of the array, hence O(1).

 Question 4
What is the worst case for linear search?
 A O(nlogn) B O(logn) C O(n) D O(1)
 A public int linearSearch(int arr[], int key, int size) { int index = -1; int i = 0; while(size > 0) { B public int linearSearch(int arr[], int key, int size) { int index = -1; int i = 0; while(size > 0) {  C public int linearSearch(int arr[], int key, int size) { int index = -1; int i = 0; while(size > 0) { D None of the mentioned