review2sol

review2sol - Computer Science 340 Reasoning about...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Computer Science 340 Reasoning about Computation Review Session 2 Friday, January 11, 2008 Problem 1 Recall the cow grazing problem from Homework 5. The cow is on a path that leads to food, but the cow doesnt know what direction the food lies in. The goal was to design an online algorithm for the cow to traverse the path and find the food. The deterministic algorithm we proposed in the solution was the following. The cow starts in an arbitrary direction for one unit of distance. If it does not find food, it comes back to the starting position and tries the other direction going 2 units of distance. Each time it comes back to the start position, it goes in the other direction for twice the distance it tried before. We argued that the competitive ratio of this algorithm was 9. Several of you got 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 a direction to traverse at random every time the cow returns to the origin. So, the cow goes distance 2 i- 1 in the i th iteration (and returns to the start if unsuccessful), but the direction of travel is picked at random at every iteration. Determine the competitive ratio of this algorithm. Solution: The algorithm is not competitive. Suppose that the field is at position 1. Compute the expected distance traveled by the algorithm in this case. The expected distance is . The expression for expected distance turns out to be 1 2 (1) + 1 4 (2(1) + 1) +...
View Full Document

Page1 / 3

review2sol - Computer Science 340 Reasoning about...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online