Question: 7.Z rewritten (as a rewritten 7.27) Let G (V, E) be a DAG, and let each edge (u, v) in E have the positive length
7.Z rewritten (as a rewritten 7.27) Let G (V, E) be a DAG, and let each edge (u, v) in E have the positive length Ecost(u, v) > 0. We think of the length function Ecost(*, ) as running in constant-time for each edge. [One way to achieve this fast access is via a |VIx IVI array Ecost l.JVI, 1. VlI. But you cannot use arrays in an algori that runs in O( E +IVI) time because |El can be much less than IV]2. Th input data unless the graph contains about |VP edges. A better way to input the data is to enhance each adjacency list Adjlu to store not only the name v of each neighbor of u, but also the edge-length of the edge (u, v). So instead of thinking of Adjlu as a list of vertex names, we think of it as a list of pairs (vertezname, edgelength), so that an element in the U hat is, we should not spend IVI2 time reading the 2 (v, Ecost(u,")), where v is a neighbor of u, and Ecost(u, v) is the numerical length of edge (u, v)] Consequently, you can use pseudocode that accesses the length via the call Ecost(u, e), and ignore the lower-level and easily solved-coding issues about how store these values in a time-space efficient way a) Present a DFS that runs in e(V] EI) time and finds, for each vertex u in V, the largest length among all paths that begin at u and end at any of G's leaf-like vertices, which have no exiting edges. For each u in V, store the solution in the fied u.longestoutof
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
