| Name: | Grader: | Score: |
For the following questions, assume that a number is represented using a fixed length of eight bits, i.e., 1 or 0, where the bits are organized as shown below, a 1 in a given position means that the given value is active and should be considered when computing the number, a 0 indicates the given value is not active:
sign
bit26 25 24 23 22 21 20
For example, the following represents the number 100 (where 0 represents the + sign and 1 represents the - sign):
0 1 1 0 0 1 0 0
For example, the following represents the number -99:
1 1 1 0 0 0 1 1
One wants to find this floor X in the least possible number of tries; a
try consists in dropping a marble from some floor (if the marble doesn't
break, you can use it for the next try, but if it breaks it is not usable
anymore). For example, it is trivial to solve the problem using a sequential
search, i.e., starting at the first floor, dropping a marble, walking down
the stairs to pick it up, going back up to the second floor, dropping the
marble again, walking down the stairs to pick it up, etc. In the worst case
for this algorithm, when all 100 floors are safe, it will take one hundred
tries. This is not the most efficient technique and it does not even use the
second marble! However, binary search is also not the best algorithm because
in its worst case, when the first 49 floors are safe, it takes 50 tries
(explain why).
In the worst case scenario, what is the least number of tries? Remember
that you have only two marbles to play with!
Describe the algorithm you used to find the least number of tries. How
can you be certain of your answer?