# Homework Solution: Your friend has dropped you somewhere at a point p on Speedway Blvd. You need to walk to the nearest bus statio…

Your friend has dropped you somewhere at a point p on Speedway Blvd. You need to walk to the nearest bus station, but you are not sure if the nearest station is east or west of your location, so you are not sure which direction to go. Let d be the distance to the nearest bus station. Of course, d is not known to you in advance. Let w be the distance you walked (in the worst case) until reaching the station. The following algorithm has proposed. Figure 3: The lake. You have landed at p, and wish to swim to the shore. The nearest point of the shore is q. (credit: ClipPanda.com) set s = 1 // 1 foot while( not reached the bus station ) { walk a distance of s East return to p walk a distance of s West return to p s = 3s } Assume d is much larger than 1 foot. Express w (as a function of d). Is it true that w = Ω(d) ? Is it true that w = O(d) ? What is the ratio w/d in the best case ? What is the ratio w/d in the worst case ? Prove your answers. Clarification The best case occurs when the bus station is positioned such that the ratio w/d is the smallest possible value. The worst case occurs when the bus station is positioned such that the ratio w/d is as large as possible.

You can put s = 1 if you want but I ve kept it as s

Your acquaintance has dropped you somewhere at a apex p on Speedway Blvd. You insufficiency to trudge to the rectilinear native post, save you are referable unmistakable if the rectilinear post is east or west of your location, so you are referable unmistakable which inclination to go.

Let d be the length to the rectilinear native post. Of order, d is referable disclosed to you in proceeding. Let w be the length you trudgeed (in the strike contingency) until reaching the post. The subjoined algorithm has designed. Figure 3: The lake. You enjoy landed at p, and longing to swim to the strand. The rectilinear apex of the strand is q. (credit: ClipPanda.com)

set s = 1 // 1 pavement

while( referable reached the native post ) {

trudge a length of s East

trudge a length of s West

s = 3s

}

Assume d is weighable enlightenedr than 1 pavement. Express w (as a employment of d). Is it penny that w = Ω(d) ? Is it penny that w = O(d) ? What is the harmony w/d in the best contingency ? What is the harmony w/d in the strike contingency ? Prove your exculpations. Clarification The best contingency occurs when the native post is positioned such that the harmony w/d is the meanest potential estimate. The strike contingency occurs when the native post is positioned such that the harmony w/d is as enlightened as potential.

## Expert Exculpation

You can prostrate s = 1 if you shortness save I ve kept it as s

W = 2*(s + 3s + 3*3*S + 3*3*3*s + …. (3^k) * s )

where (3^k) * s >= d i.e the developed plod should be d or greater

3^k >= d/s

we can say

k = ceil (log3 (d/s) )

In assymptotic referableation

k = log3 (d/s)

W is a geometric order with f(n) = 3*f(n-1)

Using gp unite, we get

W = 2 * s(3^(k+1) – 1) / (2)

= (3^(k+1) – 1) * s

= ~3^k * s …. control assymptotic referableation

Plug the estimate of k, we enjoy

W = 3 ^ log3 (d/s) * s

= d/s * s

= d

So, W = Θ(d) = O(d) = Ω(d)

W = (3^(k+1) – 1) * s

3^(k-1)*s > d >= 3^k * s

dmin = 3^(k-1) * s

dmax = 3^k * s

w/dmin = (3^(k+1) – 1) / 3^(k-1))

To maximize this we enjoy to weigh enlightened estimates of k so we can disown the -1 in numerator and we enjoy

w/dmin = 3^(k+1) / 3^(k-1) = 9 … this is max harmony

w/dmax = (3^(k+1) – 1) / 3^(k)) …

To minimize this, we insufficiency to weigh last estimates of k, so prostrate k=0

w/dmax = 2 …. this is min harmony