# Data Structure Questions and Answers-Binary Search Iterative

## Data Structure Questions and Answers-Binary Search Iterative

 Question 1
What is the advantage of recursive approach than an iterative approach?
 A Consumes less memory B Less code and easy to implement C Consumes more memory D All of the mentioned
Economics Questions answers
Question 1 Explanation:
A recursive approach is easier to understand and contains fewer lines of code.

 Question 2
Choose the appropriate code that does binary search using recursion.
 A public static int recursive(int arr[], int low, int high, int key) { int mid = low + (high - low)/2; if(arr[mid B public static int recursive(int arr[], int low, int high, int key) { int mid = low + (high + low)/2; if(arr[midpublic static int recursive(int arr[], int low, int high, int key) { int mid = low + (high - low)/2; if(arr[midReading comprehension Questions answers Question 2 Explanation:  Calculate the 'mid' value, and check if that is the key, if not, call the function again with 2 sub arrays, one with till mid-1 and the other starting from mid+1. Question 3 Given an input arr = {2, 5, 7, 99, 899}; key = 899; What is the level of recursion? A5B2C3D4English literature Questions answers Question 3 Explanation:  level 1: mid = 7 level 2: mid = 99 level 3: mid = 899(this is the key).Question 4 Given an array arr = {45, 77, 89, 90, 94, 99, 100} and key = 99; what are the mid values(corresponding array elements) in the first and second levels of recursion? A90 and 99B90 and 94 C89 and 99 D89 and 94 Management Questions answers Question 4 Explanation:  Trace the input with the binary search recursive code. Question 5What is the worst case complexity of binary search using recursion? AO(nlogn) BO(logn)CO(n) DO(n2) Geography Questions answers Question 5 Explanation:  Using the divide and conquer master theorem. There are 5 questions to complete.   Download all FREE PDF Ebook >>>CLICK HERE<<< Page 1 of 3123Next»  Search for: Iconic One Theme | Powered by Wordpress