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...

  • 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...

  • 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,...

  • (5) Let G be a graph without loops. Let n be the number of vertices and...

    (5) Let G be a graph without loops. Let n be the number of vertices and let xG(z) be its chromatic polynomial. Recall from HW5 that 2(G) is the number of cycle-free orientations of G. Show that

  • Give an efficient algorithm that takes a directed graph G = (V, E) and two vertices...

    Give an efficient algorithm that takes a directed graph G = (V, E) and two vertices u, v E V, and determines if there are at least two edge-disjoint paths in G from u to v. i.e., your algorithm should determine whether there are at least two paths from u to v in G that have no edges in common. Argue your algorithm's correctness and analyze its time complexity.

  • Q1: Here we consider finding the length of the shortest path between all pairs of nodes...

    Q1: Here we consider finding the length of the shortest path between all pairs of nodes in an undirected, weighted graph G. For simplicity, assume that the n nodes are labeled 1; 2; : : : ; n, that the weight wij of any edge e = (i; j) is positive and that there is an edge between every pair of nodes. In this question, the goal is to solve this via dynamic programming. Note that the algorithm you will...

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
ADVERTISEMENT