Consider the graph G: (V: {a, b, c, d, z}, E: {(a, b, 2), (b, c, 1),
(c, z, 3), (a, d, 3), (d, z, 3)}), where the third entry in the edge
triples is the weight of the edge. Using Dijkstra's algorithm,
modified in Ex. 9.6.16 to construct the shortest path (not just find
its length), might yield either path a, b, c, z or path a, d, z, as
both have weight 6. However, in some situations, one might desire to
have the shortest length, shortest path; that is, a, d, z might be
preferable to a, b, c, z because it has fewer edges.
(a) Suggest a simple modification to the algorithm of 9.6.16 so that
it returns the shortest length, shortest path (least number of edges
of those paths tied for shortest by weight). In the example above, it
should return a, d, z.
(b) Suggest a simple modification to return the least-weighted path of
fewest edges. That is, you now want to find the path with the fewest
edges; and in the case of ties, your algorithm should select the path
whose sum of weights is the least among the tied paths.
Hint: Think about lexicographic orders. The modifications can
be described using one sentence.