MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
The binary search algorithm can work on unsorted data in a array
A
True
B
False
C
Either A or B
D
None of the above
Explanation: 

Detailed explanation-1: -So, the answer is NO, it is not possible to use or implement Binary Search on unsorted arrays or lists, because, the repeated targeting of the mid element of one half depends on the sorted order of data structure.

Detailed explanation-2: -The most common algorithm to search an element in an unsorted array is using a linear search, checking element by element from the beginning to the end, this algorithm takes O(n) complexity. Using the front and back algorithm can take us a half of time.

Detailed explanation-3: -Binary search works by assuming the middle of the array contains the median value in the array. If it is not sorted, this assumption does not make sense, since the median can be anywhere and cutting the array in half could mean that you cut off the number you were searching for.

Detailed explanation-4: -The most efficient way of creating an unsorted binary tree from a list of items is just to take the list of items and consider element 0 the root, element 1 and 2 the left and right nodes of element 0, etc. This gives you a perfectly balanced tree with zero work.

There is 1 question to complete.