After moving to a new city, you decide to choose a walking route from your home to your new office. To get a good daily workout, your route must consist of an uphill path (for exercise) followed by a downhill path (to cool down), or just an uphill path, or just a downhill path.1 (You'll walk the same path home, so you'll get exercise one way or the other.) But you also want the shortest path that satisfies these conditions, so that you actually get to work on time. Your input consists of an undirected graph G, whose vertices represent intersections and whose edges represent road segments, along with a start vertex s and a target vertex t. Every vertex v has a value h(v), which is the height of that intersection above sea level, and each edge uv has a value l(uv), which is the length of that road segment.

(a) Describe and analyze an algorithm to find the shortest uphill-downhill walk from s to t. Assume all vertex heights are distinct.

(b) Suppose you discover that there is no path from s to t with the structure you want. Describe an algorithm to find a path from s to t that alternates between "uphill" and "downhill" subpaths as few times as possible, and has minimum length among all such paths. (There may be even shorter paths with more alternations, but you don't care about them.) Again, assume all vertex heights are distinct.

### Recently Asked Questions

- (LO 5) A manufacturer reports the following costs to produce 19,000 units in its first year of operations: Direct materials, $19 per unit, Direct labor, $15

- The same researcher also studied a third diet; the Zone diet. Her research showed that the Zone diet was MORE effective than the LEARN diet (after accounting

- (LO 5) Leeks Company's product has a contribution margin per unit of $14.10 and a contribution margin ratio of 23.5%. What is the selling price of the product?