Question

Let G be a DAG (a graph without loops) and u, v be two designated nodes...

Let G be a DAG (a graph without loops) and u, v be two designated nodes (there are many other nodes in G). In particular, each node in G is labeled with a color and multiple nodes can share the same color. A good path is one where the number of green nodes is bigger than the number of yellow nodes. Describe an efficient algorithm to count the number of good paths from u to v.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I would use a breadth-first search to check all possible paths between the two nodes. During the calculation of a given edge distance I would include a check to determine if the the edge is red or green or neither and increment a counter variable for the number of red or green edges. (Two variables, one for red edges and one for green edges) These variables would be attached to each node so just like the distance is calculated by totaling the distances from one node to the next, the number of red and green edges can be totaled along any given path.

Below is my algorithm.

Let L be an empty list that possible paths will be added to.
Let Q be a queue to store nodes to be examined

For each node in G
        mark undiscovered, set distance to infinity, set parent to null, and set        counters to 0

starting at v
initialize distance of v to be 0
add v to Q

while Q is not empty
        dequeue Q and call this node u (Current node)
        for each vertex x adjacent to u
                if x undiscovered
                        mark x as discovered
                        set x’s distance = parents u’s distance + 1
                        set x’s parent to u
                        if x is green
                                set x's green count to u's + 1
                        if yellow
                                set x's yellow count to u's + 1
                
                        add x to Q
        mark u as fully explored
        add u to L

for each element In L
        if element == v'
                if v' yellow Count < v' green Count
                        cnt++
                
Add a comment
Know the answer?
Add Answer to:
Let G be a DAG (a graph without loops) and u, v be two designated nodes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem 1: Given a graph G (V,E) a subset U S V of nodes is called...

    Problem 1: Given a graph G (V,E) a subset U S V of nodes is called a node cover if each edge in E is adjacent to at least one node in U. Given a graph, we do not know how to find the minimum node cover in an efficient manner. But if we restriet G to be a tree, then it is possible. Give a greedy algorithm that finds the minimum node cover for a tree. Analyze its correctness...

  • Suppose G is a DAG,i.e., a directed acyclic graph. Lets and t be two nodes in...

    Suppose G is a DAG,i.e., a directed acyclic graph. Lets and t be two nodes in the graph. Describe an O(n+m) algorithm that computes the number of paths from s to t . (Hint: start by topologically ordering G.)

  • NAME . You are given a strongly connected directed graph G (V, E) with positive edge...

    NAME . You are given a strongly connected directed graph G (V, E) with positive edge weights along with a particular node vo E V. Give an efficient algorithm for finding shortest paths between all pairs of nodes, with the one restriction that these paths must all pass through v (8 points)

  • Problem 1: Dynamic Programming in DAG Let G(V,E), |V| = n, be a directed acyclic graph...

    Problem 1: Dynamic Programming in DAG Let G(V,E), |V| = n, be a directed acyclic graph presented in adjacency list representation, where the vertices are labelled with numbers in the set {1, . . . , n}, and where (i, j) is and edge inplies i < j. Suppose also that each vertex has a positive value vi, 1 ≤ i ≤ n. Define the value of a path as the sum of the values of the vertices belonging to...

  • 2. Let G be an undirected graph. For every u,vE V(G), let dc(u,v) be the length of the shoertest ...

    2. Let G be an undirected graph. For every u,vE V(G), let dc(u,v) be the length of the shoertest path from u to v. The diameter of G is he maximum distance bet In other words: max (de(u, v) u,vEV(G) the running time of your algorithm 2. Let G be an undirected graph. For every u,vE V(G), let dc(u,v) be the length of the shoertest path from u to v. The diameter of G is he maximum distance bet In...

  • You are given an unweighted DAG (Directed Acyclic Graph) G, along with a start node s...

    You are given an unweighted DAG (Directed Acyclic Graph) G, along with a start node s and a target node t. Design a linear time (i.e., runtime O(IV+ EI)) dynamic programming algorithm for computing the number of all paths (not necessarily shortest) from s to t.

  • Consider an unweighted, undirected graph G = 〈V, E). The neighbourhood of a node u E V in the gr...

    This question needs to be done using pseudocode (not any particular programming language). Thanks Consider an unweighted, undirected graph G = 〈V, E). The neighbourhood of a node u E V in the graph is the set of all nodes that are adjacent (or directly connected) to v. Subsequently, we can define the neighbourhood degree of the node v as the sum of the degrees of all its neighbours (those nodes that are directly connects to v) (a) Design an...

  • Which of the following is TRUE about Topological Sorting? Topological Sort can be used as a...

    Which of the following is TRUE about Topological Sorting? Topological Sort can be used as a subroutine to find shortest paths in a weighted DAG in time O(V+E); in particular, the time does not depend on the magnitudes of the weights on the edges, and the weights on the edges may be negative. A Topological Sort algorithm sorts the nodes of an arbitrary directed graph G in an order that is consistent with all the paths in G, that is...

  • Consider an unweighted, undirected graph G = 〈V, E). The neighbourhood of a node u E V in the gr...

    Consider an unweighted, undirected graph G = 〈V, E). The neighbourhood of a node u E V in the graph is the set of all nodes that are adjacent (or directly connected) to v. Subsequently, we can define the neighbourhood degree of the node v as the sum of the degrees of all its neighbours (those nodes that are directly connects to v) (a) Design an algorithm that returns a list containing the neighbourhood degree for each node v V,...

  • You are given a weighted graph G, two designated vertices s and t. Your goal is...

    You are given a weighted graph G, two designated vertices s and t. Your goal is to find a path from s to t in which the minimum edge weight is maximized i.e. if there are two paths with weights 10→1→5 and 2→7→3 then the second path is considered better since the minimum weight (2) is greater than the minimum weight of the first (1). Describe an efficient algorithm to solve this problem and show its complexity.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT