Computer Science 340Reasoning about ComputationReview Session 2Friday, January 11, 2008Problem 1Recall the cow grazing problem from Homework 5. The cow is on a path that leads tofood, but the cow doesn’t know what direction the food lies in. The goal was to design anonline algorithm for the cow to traverse the path and find the food.The deterministic algorithm we proposed in the solution was the following.The cowstarts in an arbitrary direction for one unit of distance. If it does not find food, it comesback to the starting position and tries the other direction going 2 units of distance. Eachtime it comes back to the start position, it goes in the other direction for twice the distanceit tried before. We argued that the competitive ratio of this algorithm was 9. Several of yougot this, or some variant of this idea.Next we asked you to design a randomized algorithm with better competitive ratio.Several students proposed randomizing the previous deterministic algorithm by picking adirection to traverse at random every time the cow returns to the origin. So, the cow goesdistance 2i-1in theith iteration (and returns to the start if unsuccessful), but the directionof travel is picked at random at every iteration.Determine the competitive ratio of thisalgorithm.Solution:The algorithm is not competitive. Suppose that the field is at position 1. Compute theexpected distance traveled by the algorithm in this case. The expected distance is∞. Theexpression for expected distance turns out to be12(1) +14

This
preview
has intentionally blurred sections.
Sign up to view the full version.