What will be the necessary condition to get the desired element from a given…

2024

What will be the necessary condition to get the desired element from a given array by using the following algorithms?

If LOC = -1 do ITEM NOT FOUND

Do_Something(DATA, N, ITEM,LOC)

initialize Counter set LOC=0, LOW=0, HI= N-1

[Search for item]

Repeat while LOWs HI

MID = (LOW+HI)/2

IF ITEM = DATA[MID] do

LOC+MID

Return LOC

IF ITEM = DATA [MID}

HI = MID-1

ELSE

LOW = MID+1

  1. A.

    the elements should contain more than one element

  2. B.

    the array should contain more than one element

  3. C.

    The elements is an array should be in the sorted form.

  4. D.

    No pre-condition is required for the algorithm to work

Attempted by 55 students.

Show answer & explanation

Correct answer: C

This is the algorithm for binary search, and it is a necessary condition for binary search that the entered data should be in a sorted form

Explore the full course: Accenture Preparation