Question #774

1 b ← 0

2 e ← |a|-1

3 repeat

4 m ← floor((b+e)/2)

5 if (a[m] < k) then

6 b ← m + 1

7 else if (k < a[m]) then

8 e ← m - 1

9 end if

10 until (a[m]=k) or (e<b)

11 f ← a[m]=k

and the answer page looks like this

1: comments line# b e m k f a

a[0] a[1]a[2][3]

pre ? ? ? 3 ? 0 2 4 8

2: comments line# b e m k f a

a[0] a[1] a[2] a[3]

pre ? ? ? 9 ? 0 2 4 8

3: comments line# b e m k f a

a[0] a[1] a[2] a[3]

pre ? ? ? 9 ? 0 2 4 8

2 e ← |a|-1

3 repeat

4 m ← floor((b+e)/2)

5 if (a[m] < k) then

6 b ← m + 1

7 else if (k < a[m]) then

8 e ← m - 1

9 end if

10 until (a[m]=k) or (e<b)

11 f ← a[m]=k

and the answer page looks like this

1: comments line# b e m k f a

a[0] a[1]a[2][3]

pre ? ? ? 3 ? 0 2 4 8

2: comments line# b e m k f a

a[0] a[1] a[2] a[3]

pre ? ? ? 9 ? 0 2 4 8

3: comments line# b e m k f a

a[0] a[1] a[2] a[3]

pre ? ? ? 9 ? 0 2 4 8

Expert's answer

Please, clarify your question or submit it to our site as an assignment, just follow this link and our experts will help you.

Learn more about our help with Assignments: Programming & Computer Science

## Comments

## Leave a comment