Answer for part b)
DAG are Directed Acyclic Graphs. Graph contains nodes and nodes are connected with eaach other through edges. These edges in DAG are directed, meaning they will have a directed arrow in the end of the edge showing the way in which we can go if we are at particular node.
Now as per the question we need to prove that if a DAG should contain atleast 1 sink then it should also have atleast one source.
Lets take an example of 2 Nodes creating a DAG as shown in the picture:
If we take this into consideration we can see that to make it a DAG the node from which the sink is receiving an incoming edge needs to be the source as the sink wont be able to produce any out going node back to that single node which I have labeled as source so it can be proved using this simple example that if there is a DAG and containing atleast one sink then it will definitely have atleast one source.
Answer for part c)
This algorithm which is written can be said to titled as
"Listing all reachable nodes of DAG "
. Lets take a simple example to understand the
flow of link list L and Stack S using the following
picture.
Candier this a DAG we will be taking for part c). I will be jotting down the List L and Stack S intermeditae and final results by showing the data they store at each step.
Initially Stack S contains all sources and hence we can say that
S -> 1 // SHowing S contains Node 1
L -> $ // $ sign will depict NULL
Step 1.
u = 1, S-> $ // Popping from the stack and saving in u
L -> 1 // Pushing u to the list
S -> 2,3 // removing the edges and pushing those with only No more incoming nodes in S
Step 2.
u = 2, S->3 // Poppd the value from S
L -> 1,2 // Pushing u to the list
S -> 3 // Removed only the edges going out from 2 and no node is pushed back
Step 3.
u = 3, S->$ // Popped the value from S
L -> 1,2,3 // Pushing u to the list
S -> 4,5 // Pushed 4 and 5 into the S
Step 4.
u = 4, S->5 // Popped the value from S
L -> 1,2,3,4 // Pushing u to the list
S -> 6,5 // Pushed 6 into the S
Step 5.
u = 6, S->5 // Popped the value from S
L -> 1,2,3,4,6 // Pushing u to the list
S -> 5 // Nothing pushed into S as Node 6 is sink.
Step 6.
u = 5, S->$ // Popped the value from S
L -> 1,2,3,4,6,5 // Pushing u to the list
S -> 7 // Pushed Node 7 into the S
Step 7.
u = 7, S -> $ // Popped the value from S
L -> 1,2,3,4,6,5,7 // Pushing u to the list
S -> $ // Nothing pushed into S as Node 7 is sink.
After this L is returned which contains all reachable nodes of given DAG by removing the multi-edges and moving in a hybrid BFS and DFS fashion.
It would have been easier to explain it verbally. I have tried my level best to explain it in the best way possible. Hope I gave your answer.Happy learning and feel free to raise any question if needed.
(b) A source in a directed graph is a node with no incoming edges. A sink...
5 Network Flow, 90p. Consider the below flow network, with s the source and t the sink. 5 4 1. (10p) Draw a flow with value 8. (You may write it on top of the edges in the graph above, or draw a new graph.) You are not required to show how you construct the flow (though it may help you to apply say the Edmonds-Karp algorithm). 2. (5p) List a cut with capacity 8. (You may draw it in...
graph below represents a network and the capacities are the sumber written on edges. The source is node a, and the target is node h. a. 10 (e) Show a fow of size 7 units going from the source a to the target h. (Write on the graph, next to the capacity, how many units of flow go through each edge.) (b) Consider the cut (L, R), wbere L (o) and R-(d.e.cf.s.Al, Indicate the edges crosig show that this cut...
3. The indegree of a vertex u is the number of incoming edges into u, .e, edges of the form (v,u) for some vertex v Consider the following algorithm that takes the adjacency list Alvi, v2, n] of a directed graph G as input and outputs an array containing all indegrees. An adjacency list Alvi, v.. /n] is an array indexed by the vertices in the graph. Each entry Alv, contains the list of neighbors of v) procedure Indegree(Alvi, v2,......
Viterbi algorithm We can use dynamic programming on a directed graph G = (V, E) for speech recognition. Each edge (u, v) in E is labeled with a sound s(u, v) from a finite set S of sounds. The labeled graph is a formal model of a person speaking a restricted language. Each path in the graph starting from a distinguished vertex v0 in V corresponds to a possible sequence of sounds produced by the model. The label of a...
Say that we have an undirected graph G(V, E) and a pair of vertices s, t and a vertex v that we call a a desired middle vertex . We wish to find out if there exists a simple path (every vertex appears at most once) from s to t that goes via v. Create a flow network by making v a source. Add a new vertex Z as a sink. Join s, t with two directed edges of capacity...
2) Let G ME) be an undirected Graph. A node cover of G is a subset U of the vertex set V such that every edge in E is incident to at least one vertex in U. A minimum node cover MNC) is one with the lowest number of vertices. For example {1,3,5,6is a node cover for the following graph, but 2,3,5} is a min node cover Consider the following Greedy algorithm for this problem: Algorithm NodeCover (V,E) Uempty While...
et NV,E] be a capacitated directed network with unique fixed source and unique fixed sink, no edges into the source, and no edges out of the sink. To eadh vertex u,e V, assign a number μj equal to 0 or-1. To each edge (Unuj)e E, assign a number yy defined by yy -max (0, H, - Hj). (See the discussion immediately preceding Example 10.) a. Prove that-t +pj + yi,2 0 for all i and j. b. Prove that yy...
Problem 6 (20 points). Let G- (V,E) be a directed Let E' be another set of edges on V with edge length '(e) >0 for any e EE. Let s,t EV. Design an algorithm runs in O(lV+ E) time to find an edge e'e E' whose addition to G will result in the maximum decrease of the distance from s to t. Explain why your algorithms runs in O(V2+E') time. graph with edge length l(e) >0 for any e E...
Suppose we are given a directed acyclic graph G with a unique source and a unique sink t. A vertex v ¢ {s,t} is called an (s,t)-cut vertex if every path from s to t passes through v, or equivalently, if deleting v makes t unreachable from s. Describe and analyze an algorithm to find every (s, t)-cut vertex in G t