Data Structure Questions and Answers-Binary Search Iterative

 

 Help authour, Buy PDF Ebook   >>>Click Here<<<

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[mid
public 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?
A
5
B
2
C
3
D
4
English 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?
A
90 and 99
B
90 and 94
C
89 and 99
D
89 and 94
Management Questions answers
Question 4 Explanation: 
Trace the input with the binary search recursive code.

Question 5
What is the worst case complexity of binary search using recursion?
A
O(nlogn)
B
O(logn)
C
O(n)
D
O(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<<<

Iconic One Theme | Powered by Wordpress