- Search through the array of int vals =
{ 1, 2, 3, 4, 6, 9, 10, 11, 12, 14, 15, 17, 18, 19, 20};
- What is the length of the array?
- What is the position of the first value?
- What is the position of the last value?
- Where is the middle of the values you are looking through?
What number is in the middle?
- Compare your number to the middle value, are you too low, too high or just right?
- Fill in the table below:
index of low |
index of high |
middle position |
middle value |
low high or just right? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- How do you declare an array of integers?
__________________________________________
- Find the length of the array
- What is the position of the first value?
- What is the position of the last value?
- What is the equation to find the middle of the values you are looking through?
___________________________________________
- Write the if statement to see if you're too low, too high or just right
if(_______________________)
//too low
else if (__________________________)
// too high
else return ______
// just right
- How do you calculate the new low and high indices if:
- the value checked is too low
low = ______, high = ____
- the value checked is too high
low = ______, high = ____
|