Imagine that you are facing an infinitely long wall, and you need to reach the only door in the wall. You may walk along the wall to your left or to your right, and at any time you may turn and walk in the opposite direction. You are in fog, so you only know where the door is when you are right in front of it. Assume that the door is an (unknown, but finite) integer number of steps away. As a function of the (possibly unknown) distance to the door, give an algorithm and cost for the minimum number of steps (in the worst case) that you must walk to reach the door in the following situations. For each situation, you should describe the (best) procedure that you could follow and analyze its worst-case cost: (a) You know the door is to your left. (b) You don’t know where the door is, but you know that it is exactly n steps away. (c) You don’t know where the door is, but you know that it is at most n steps away
Imagine that you are facing an infinitely long wall, and you need to reach the only
door in the wall. You may walk along the wall to your left or to your right, and at
any time you may turn and walk in the opposite direction. You are in fog, so you
only know where the door is when you are right in front of it. Assume that the door
is an (unknown, but finite) integer number of steps away. As a function of the
(possibly unknown) distance to the door, give an
number of steps (in the worst case) that you must walk to reach the door in the
following situations. For each situation, you should describe the (best) procedure
that you could follow and analyze its worst-case cost:
(a) You know the door is to your left.
(b) You don’t know where the door is, but you know that it is exactly n steps
away.
(c) You don’t know where the door is, but you know that it is at most n steps
away
Trending now
This is a popular solution!
Step by step
Solved in 3 steps