Question

Search for 4 in the sequence {3,5,7,8,9,12,21,25}, by working through each step of the algorithm given...

Search for 4 in the sequence {3,5,7,8,9,12,21,25}, by working through each step of the algorithm given below. Specify the values of i, j, m and am in each step.

procedure binary search (x: integer, a1,a2,...,an: increasing integers) i := 1 {i is left endpoint of search interval } j := n {j is right endpoint of search interval } while i < j m := b(i + j)/2c if x > am then i := m + 1 else j := m if x = ai then location := i else location := 0 return (location)

Fill your answers in the following worksheet. You may not use all of the blanks.

Steps

i < j

m

am

x > am

i

j

0

T or F

N/A

N/A

T or F

1

8

1

2

3

4

5

6

7

8

Return

location =

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Search for 4 in the sequence {3,5,7,8,9,12,21,25}, by working through each step of the algorithm given...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT