Assume that the adjacency list representing a directed graph G has already been constructed.
Show how to determine whether G contains a universal sink, that is a vertex with in-degree |V | − 1 and out-degree 0, in time O(|V |).
**Please explain in detail
We are looking for a universal sink i.e. a vertex in degree of |
V | −1 and out degree of zero
In the adjacent matrix the elements the element in row i represent
the edges that are out-going from node i
to other nodes. And the elements in column j represent the edges
that are in-coming to node j.
If vertex i is a universal sink according to the definition, the
i-th row of the adjacency-matrix will be all “0”, and
the i-th column will be all “1” except the aii entry, and clearly
there is only one such vertex.
We then describe an algorithm to find out if a universal sink really exist.
Starts from a11.
The u-row must contain 0’s only
The u-column must contain 1’s only
If current entry aij = 0 then j = j + 1 (take one step right); if
aij = 1 then i = i +1 (take one step down).
In this way, it will stop at an entry akn of the last row or ank of the last column (n = |V|, 1 ≦ k ≦|V|).
Check if vertex k satisfies the definition of universal sink, if yes then we found it, if no then there is no universal sink.
Since we always make a step right or down, and checking if a vertex is a universal sink can be done in O(V), the total running time is O(V).
If there is no universal sink, this algorithm won’t return any vertex.
The algorithm terminates once we find a row of all zero’s
whether that row represents a universal sink or not, thus
guaranteeing
O(V ) running time.
If there is a universal sink u, the path starts from a11 will definitely meet u-th column or u-th row at some entry.
Once it’s on track, it can’t get out of the track and will finally stop at the right entry.
Repeating the above procedure, examining one row at a time from
vertices that have not yet been
eliminated, we can find whether a universal sink exist or not.
Thus, finding whether a graph has a
universal sink or not, can be determined in O(V ) time.
Assume that the adjacency list representing a directed graph G has already been constructed. Show how...
8, (10 pts) Show that given a directed graph G = (V,E) already stored in adjacency matrix form, determining if there is a vertex with in-degree n - 1 and out-degree 0 can be done in O(n) time where n is the number of vertices in V. 8, (10 pts) Show that given a directed graph G = (V,E) already stored in adjacency matrix form, determining if there is a vertex with in-degree n - 1 and out-degree 0 can...
Exercise (15 points) Consider an adjacency-list representation of a directed graph G=(V.E). a) Propose in pseudocode an algorithm A to compute the in-degree of each vertex in V. b) What is the time complexity of A? c) Propose in pseudocode an algorithm B to compute the out-degree of each vertex in V. d) What is the time complexity of B?
For a directed graph the in-degree of a vertex is the number of edges it has coming in to it, and the out- degree is the number of edges it has coming out. (a) Let G[i,j] be the adjacency matrix representation of a directed graph, write pseudocode (in the same detail as the text book) to compute the in-degree and out-degree of every vertex in the Page 1 of 2 CSC 375 Homework 3 Spring 2020 directed graph. Store results...
22.1-1 Given an adjacency-list representation of a directed graph, how long does it take to compute the out-degree of every vertex? How long does it take to compute the in-degrees?
114points Let G- (V,E) be a directed graph. The in-degree of a vertex v is the number of edges (a) Design an algorithm (give pseudocode) that, given a vertex v EV, computes the in-degree of v under (b) Design an algorithm (give pseudocode) that, given a vertex v E V, computes the in-degree of v incident into v. the assumption that G is represented by an adjacency list. Give an analysis of your algorithm. under the assumption that G is...
Q2. Show the execution trace of DFS on the following directed graph. You must show discovery time v.d, finish time v.f, and the v.color for each node as the algorithm progresses. Indicate all tree edges, back edges, forward edges, and cross edges when the final DFS forest is constructed. Assume that the edges going out from a vertex are processed in alphabetical order and that each adjacency list is ordered alphabetically.
Reachability. You are given a connected undirected graph G = (V, E ) as an adjacency list. The graph G might not be connected. You want to fill-in a two-dimensional array R[,] so that R[u,v] is 1 if there is a path from vertex u to vertex v. If no such path exists, then R[u,v] is 0. From this two-dimensional array, you can determine whether vertex u is reachable from vertex v in O(1) time for any pair of vertices...
Consider the following directed graph, which is given in adjacency list form and where vertexes have numerical labels: 1: 2, 4, 6 2: 4, 5 3: 1, 2, 6, 9 4: 5 5: 4, 7 6: 1, 5, 7 7: 3, 5 8: 2, 6, 7 9: 1, 7 The first line indicates that the graph contains a directed edge from vertex 1 to vertex 2, from 1 to vertex 4, and 1 to 6, and likewise for subsequent lines....
3. Given a directed graph G < V E >, we define its transpose Gr < V.E1 > to be the graph such that ET-{ < v, u >:< u, v >EE). In other words, GT has the same number of edges as in G, but the directions of the edges are reversed. Draw the transpose of the following graph: ta Perform DFS on the original graph G, and write down the start and finish times for each vertex in...
3. (8 points-7+1) Figure 4 shows an undirected graph G. Assume that the adjacency list lists the edges in alphabetical order. Figure 3: Graph for P3 (a) Apply depth first search (DFS) to graph G, and show the discovery and finish times of each vertex. In the main-loop of DFS, check the vertices in alphabetical the form dsc/fin, where dsc is the discovery time and fin is the finish time. (b) Draw the DFS tree obtained. 3. (8 points-7+1) Figure...