Question

Door in a wall You are facing a wall that stretches infinitely in both directions. There...

Door in a wall You are facing a wall that stretches infinitely in both directions.
There is a door in the wall, but you know neither how far away nor in
which direction. You can see the door only when you are right next to it. Design
an algorithm that enables you to reach the door by walking at most O(n)
steps where n is the (unknown to you) number of steps between your initial
position and the door.

please provide the solution in detail steps

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Step1 ) The main idea here is to walk intermittently right and left going each time exponentially farther from the initial position.

Step2 ) A simple implementation of this idea is to do the following until the door is reached: For i=0,1,..., make 2i steps to the right, return to the initial position, make 2i steps to the left, and return to the initial position again. Let 2(k−1) < n ≤ 2k. The number of steps this algorithm will need to find the door can be estimated above as follows:

some math :

k-1

In the above math, the 4 is meant to calculate the number of full steps that represent a full search. So let's says we're at i = 1.

We start at x = 0. We go to 2 ^ 1 = 2. That's 2 steps. Then back to 0. Another 2 steps. Then to -2, then back to 0. A total of 8 steps, or 4 x 2 ^ 1

4 x 2 ^ i = number of steps in an unsuccessful search where we return to the origin to commence a larger search, since we can only traverse left and right, and not teleport

the kth iteration is when we find our door. The worst case is when the door is at n to the left where n = 2^k steps.

So what happens when we get into this iteration?

We start at x = 0, we go to 2^k to the right, then back to 0, then to the left to -2^k. A total traversal of 3 x 2 ^ k steps.

As to why it's compared to 7 * 2 ^ k, we know that the ith search term is 2 ^ (k - 1) or everything before. We can substitute 7*2^k with 7n based on our previous definition regarding k - 1 vs k

And we can also use the fact that 2^k = 2 x 2^(k-1) in our abstractions.

Per 2^(k−1) < n is supposed, so you can substitute 2^(k−1) by n and get 14*2^(k−1) < 14n

Hence the number of steps made by the algorithm is in O(n).

Add a comment
Know the answer?
Add Answer to:
Door in a wall You are facing a wall that stretches infinitely in both directions. There...
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
  • Parts A, B. Pleasee! ine treasure map in the rigure gives the following directions to the...

    Parts A, B. Pleasee! ine treasure map in the rigure gives the following directions to the buried treasure: "Start at the old oak tree, walk due north for 540 paces, then due east for 150 paces. Dig." But when you arrive, you find an angry dragon just north of the tree. To avoid the dragon, you set off along the yellow brick road at an angle 60° east of north. After walking 300 paces you see an nnening through the...

  • What did I do wrong? How do I get the right answer? You are walking around...

    What did I do wrong? How do I get the right answer? You are walking around your neighborhood and you see a child on top of a roof of a building kick a soccer ball. The soccer ball is kicked at 47 degree from the edge of the building with an initial velocity of 13 m/s and lands 59 meters away from the wall. How tall is the building that the child is standing on? 57.0 What information is given,...

  • please solve both. thank you! A mass of 1.25 kg stretches a spring 0.06 m. The...

    please solve both. thank you! A mass of 1.25 kg stretches a spring 0.06 m. The mass is in a medium that exerts a viscous resistance of 56 N when the mass has a velocity of 2 . The viscous resistance is proportional to the speed of the object. Suppose the object is displaced an additional 0.03 m and released. Find an function to express the object's displacement from the spring's equilibrium position, in m after t seconds. Let positive...

  • PHYS 121 – Special Problem 1 Multiple Representations and Kinematics Two children are playing a game...

    PHYS 121 – Special Problem 1 Multiple Representations and Kinematics Two children are playing a game where they run towards each other and see who can reach a toy that is somewhere between them. In the beginning, Charlie is 23.7 m away from the toy, running towards it at a speed of 0.770 m/s, and is speeding up. At the same time, Amy is 12.5 m away from the toy, is running towards it in the opposite direction as Charlie...

  • In this question, you will test, using a backtracking algorithm, if a mouse can escape from...

    In this question, you will test, using a backtracking algorithm, if a mouse can escape from a rectangular maze. To ensure consistency of design, start your solution with maze_start.c. The backtracking algorithm helps the mouse by systematically trying all the routes through the maze until it either finds the escape hatch or exhausts all possible routes (and concludes that the mouse is trapped in the maze). If the backtracking algorithm finds a dead end, it retraces its path until it...

  • I need aome help with this part of my lab. thank you! Kirchoff's Laws 4. Now...

    I need aome help with this part of my lab. thank you! Kirchoff's Laws 4. Now click on this link, which is another circuit I modified and created for this lab: http://tinyurl.com/y8toda84 A. Do not Click run/Stop. This is a circuit that has elements that are neither series nor parallel, as well as multiple voltage sources. The best way for us to analyze this circuit is to use Kirchoff's laws. From the text here are Kirchoff's laws: 1) The sum...

  • Microscale techniques: In today's experiment we will be using very small amounts of chemical reactants. This...

    Microscale techniques: In today's experiment we will be using very small amounts of chemical reactants. This method is generally less expensive and more environmentally-friendly than traditional "test tube" chemistry. Some of the waste products produced in today's experiment, particularly those containing lead and barium, are harmful to the environment. By using such small amounts of chemical reactants we generate far less waste than by using larger scale methods. Procedure 1. Put on your safety goggles. Be sure to wear them...

  • Pendulum Clocks Are Very Important...

    1. Pendulum clocks are very important for the history of exploration.   Accurate time was the best way to determine one's longitude, since the time of sunrise or sunset depends sensitively on your longitude. In this regard, the great enemy of accuracy was thermal expansion of the pendulum used for the chronometer. We are considering a large mass attached at the end of a brass rod.   The mass at the end is much greater than the mass of the rod, so we...

  • Situation 1: You have a metal cube, measuring L on each side. The metal is in electrostatic equil...

    Situation 1: You have a metal cube, measuring L on each side. The metal is in electrostatic equilibrium and has a net 4. charge of Q,. The cube has a cavity within it, however-where there is no metal. The shape of this cavity is not known. Somewhere within the cavity rests a point charge, q,. Its exact location is unknown, but it is not in contact with the inner wall of the cavity At a certain point P, on the...

  • Please try to answer all questions and show work. Thank you. 1. A baseball player is...

    Please try to answer all questions and show work. Thank you. 1. A baseball player is warming up and tosses a ball straight up into the air. The ball travels up until it reaches some maximum height, and then falls back down to the player's hand. If we neglect air resistance, then the magnitude of the acceleration of the ball is? A. largest the moment after it leaves the players hand. B. smallgst the moment after it leaves the player's...

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