Question 1,2,4 :- ----------------------------------- Please check comments in Programme #include /** * Method for Linear Search * Loop through given array and search for given key * IF found return index and stop * else -1 will be returned at the end * */ int search(int array[],int key,int size){ int index = -1; for (int c = 0; c < size; c++) { if (array[c] == key) /* if required element found */ { printf(\"%d is present at location %d.\ \", key, c+1); index = c; break; } } if(index == -1) printf(\"%d is not found.\ \", key); return index; } /** * Function for Binary search * Binary search is used only for sorted arrays * Check key with element at middle position * if key == then return middle positon * if key > middle position , apply same for sub array range from [middle...last] * if key < middle position , apply same for sub array range from [0..middle] * */ int binary_search(int array[],int key,int start,int end){ int index = -1; int first = start; int last = end; int middle = (first+last)/2; while (first <= last) { //Print array between first nad last for each step printf(\"Start binary search step.\ \"); for(int i = first ; i < last ; i++){ printf(\"Binary search step element.%d\ \",array[i]); } printf(\"Stop binary search step.\ \"); if (array[middle] < key) first = middle + 1; else if (array[middle] == key) { index = middle; printf(\"%d found at location %d.\ \", key, middle+1); break; } else last = middle - 1; middle = (first + last)/2; } return index; } /** * Recursive linear search * Instead of for loop call same method with next index * first pass 0, check if key found at index 0, if not found call same method with index 1 ..... */ int linear_search_recursive(int array[],int key,int size,int index){ if(array[index] == key){ printf(\"%d found at location %d.\ \",key, index); return index; } else if (index >= size-1){ return -1; } else{ return linear_search_recursive(array,key,size,++index); } } /** * Recursive Binary Search * Recursively call Binary Search , check key found at element middle * if key == then return middle positon * if key > middle position , call recursive method for sub array range from [middle...last] * if key < middle position , call recursive method for sub array range from [0..middle] */ int binary_search_recursive(int array[],int key,int start,int end){ //Key not found if(start> end){ return -1; } int index = -1; int first = start; int last = end; int middle = (first+last)/2; //Print array between first nad last for each step printf(\"Start binary search step.\ \"); for(int i = first ; i < last ; i++){ printf(\"Binary search step element.%d\ \",array[i]); } printf(\"Stop binary search step.\ \"); if (array[middle] < key){ first = middle + 1; return binary_search_recursive(array,key,first,last) ; }else if (array[middle] == key) { printf(\"%d found at location %d.\ \", key, middle+1); return middle; } else{ last = middle - 1; return binary_search_recursive(array,key,first,last) ; } return -1; } /** *Function t.