MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
The following is pseudocode for which algorithm?look at middle of arrayif element you’re looking for return trueelse if element is to left search left half of arrayelse if element is to right search right half of arrayelse return false
A
linear
B
binary
C
bubble
D
merge
Explanation: 

Detailed explanation-1: -Binary Search Pseudocode We are given an input array that is supposed to be sorted in ascending order. We take two variables which will act as a pointer i.e, beg, and end. Beg will be assigned with 0 and the end will be assigned to the last index of the array.

Detailed explanation-2: -The Worst Case occurs when the target element is the last element in the array or not in the array. In this case, we have to traverse the entire array, and so the number of comparisons will be N. So, the time complexity will be O(N) .

Detailed explanation-3: -In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array.

Detailed explanation-4: -The worst case is when the value is not in the list (or occurs only once at the end of the list), in which case n comparisons are needed. (for example, for n = 2 this is 1, corresponding to a single if-then-else construct).

There is 1 question to complete.