MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Consider this list of numbers L:3 4 5 6 7 8 9. Which number would be checked first in a binary search?
A
6
B
3
C
9
D
4
Explanation: 

Detailed explanation-1: -Binary search works on sorted arrays. Binary search begins by comparing an element in the middle of the array with the target value.

Detailed explanation-2: -Binary search for finding the first occurrence The middle element will be the first occurrence in two situations: 1) target == A[mid] and target > A[mid-1] i.e. when first occurrence is present somewhere in the middle 2) mid == 0 and A[mid] == target i.e. when first occurrence is present at the first position.

Detailed explanation-3: -A binary search is a search algorithm based on divide and rule. That finds the middle element of the structure and compares and uses recursive calls to the same algorithm for inequality. Here, we are given a singly linked list and an element to be found using a binary search.

Detailed explanation-4: -Example Binary Search You have an array of 10 digits, and the element 59 needs to be found. All the elements are marked with the index from 0 – 9. Now, the middle of the array is calculated. To do so, you take the left and rightmost values of the index and divide them by 2.

There is 1 question to complete.