Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Explain how we can apply Binary Search algorithm either directly or indirectly i

ID: 3702211 • Letter: E

Question

Explain how we can apply Binary Search algorithm either directly or indirectly in the following cases: a) Array1 is an array of sorted integers numbers: (You must choose an element to show the steps) Array1: 157 13 1622 38 55 70 90 b) Array2 is an array of unsorted integers numbers: (You can choose an element to show the steps) Array2: 300 20 121 30 110 25 122 200 250 20 c) Array3 is an array of Strings The order of sorting is alphabetical (e.g. "AA" before "BC" and "AA" before "AB"). (You can choose an element to show the steps)

Explanation / Answer

Question a

Array1 is an array of sorted integers numbers

1 5 7 13 16 22 38 55 70 90

Let us choose a number say 5

The total number of element is 10

Middle element is 22

so the 5 < 22

We will search the left side

New array is

1 5 7 13 16

Middle element is 7

so the 5 < 7

we will search the left side

New array is

1 5

Middle element is 1

so the 5 > 1

we will search the right side

New array is 5

Middle element is 5

so 5==5

Match Found

Question b

Array 2 is an array of unsorted integer numbers

300 20 121 30 110 25 122 200 250 20

let us take an element say 30

Total number of element 10

Middle element 25

so 30 > 25

It will take the right hand side of the element.Eventually it will fail.The main reason for it that to use binary search algorithm the array has to be in sorted manner.

Question c

The array elements are

"AA" "AB" "BA" "BC" "CN" "FA" "KF" "LZ" "MN" "ZN"

Total number of elements is 10

Let us take an element say "BC"

Middle Element is "FA"

So as BC < FA

the new array is

AA AB BA BC CN

Middle element is BA

So as BC > BA

The new array is

BC CN

Middle Element BC

So BC==BC

Match Found

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote