Solution Found!

You are given a directed graph in which each node u V has an associated price pu which

Chapter 3, Problem 3.25

(choose chapter or problem)

Get Unlimited Answers
QUESTION:

You are given a directed graph in which each node u V has an associated price pu which is apositive integer. Define the array cost as follows: for each u V ,cost[u] = price of the cheapest node reachable from u (including u itself).For instance, in the graph below (with prices shown for each vertex), the cost values of thenodes A, B, C, D, E, F are 2, 1, 4, 1, 4, 5, respectively.Your goal is to design an algorithm that fills in the entire cost array (i.e., for all vertices).(a) Give a linear-time algorithm that works for directed acyclic graphs. (Hint: Handle thevertices in a particular order.)(b) Extend this to a linear-time algorithm that works for all directed graphs. (Hint: Recall thetwo-tiered structure of directed graphs.)

Questions & Answers

QUESTION:

You are given a directed graph in which each node u V has an associated price pu which is apositive integer. Define the array cost as follows: for each u V ,cost[u] = price of the cheapest node reachable from u (including u itself).For instance, in the graph below (with prices shown for each vertex), the cost values of thenodes A, B, C, D, E, F are 2, 1, 4, 1, 4, 5, respectively.Your goal is to design an algorithm that fills in the entire cost array (i.e., for all vertices).(a) Give a linear-time algorithm that works for directed acyclic graphs. (Hint: Handle thevertices in a particular order.)(b) Extend this to a linear-time algorithm that works for all directed graphs. (Hint: Recall thetwo-tiered structure of directed graphs.)

ANSWER:

Step 1 of 2

(a)

Given a directed graph with cost values of the nodes. The Directed Acyclic Graph (DAG) algorithm for filling the entire cost array is given below.

Algorithm:

The node   has edges to the nodes  . The nodes are reachable from the node . It can be computed as follows.

.

Here,  is the edge values and  is the price value, it is a positive integer.

1.  Start

2.  It can iteratively compute the cost values of the nodes  before computing .

3.  The DAG computes the cost values in reverse topological sort order.

4.  for each , apply a reverse topological sort to the following.

5.

6.  END for

The algorithm uses the sorting of the vertices in topological order. So, the running time of the topological sorting is linear

Add to cart


Study Tools You Might Need

Not The Solution You Need? Search for Your Answer Here:

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back