Dear Student,
Let G is a directed Graph with v vertices and e edges.
a) Pseudocode for computing in-degrees and out-degrees.
/**********************code start here ************************/
degree( G[][], int v)
int in[v] , out[v]
// initialize every index of in[] and out[] with 0
for i <-- 0 to e:
for j <-- 0 to e:
if G[i][j] equals 1:
in[i] = in[i] + 1
out[j] = out[j] + 1
// end of if
// end of for
// end of for
//end of degree
b) Calculating time complexity of above algorithm if graph has n vertices.
degree( G[][], int v) // O(1)
int in[v] , out[v] //O(1)
// initialize every index of in[] and out[] with 0
for i <-- 0 to e: //O(n)
for j <-- 0 to e: // O(n)
if G[i][j] equals 1: // O(1)
in[i] = in[i] + 1 // O(1)
out[j] = out[j] + 1 // O(1)
// end of if
// end of for
// end of for
//end of degree
Total Time complexity = 1 + 1 + n*n(1 +1 +1) // n*n because, for every iteration in first loop, second loop is running n times
=
= O() [ as is the biggest term in the above equation]
For a directed graph the in-degree of a vertex is the number of edges it has...
5. The in-degree of a vertex in a directed graph is the number of edges directed into it. Here is an algorithm for labeling each vertex with its in-degree, given an adjacency-list representation of the graph. for each vertex i: i.indegree = 0 for each vertex i: for each neighbor j of i: j.indegree = j.indegree + 1 Label each line with a big-bound on the time spent at the line over the entire run on the graph. Assume that...
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...
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,......
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?
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...
Hello, I'd like someone to help me create these, thanks! 1. Type Vertex Create and document type Vertex. Each vertex v has the following pieces of information. A pointer to a linked list of edges listing all edges that are incident on v. This list is called an adjacency list. A real number indicating v's shortest distance from the start vertex. This number is −1 if the distance is not yet known. A vertex number u. The shortest path from...
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...
Problem 3 (15 points). Let G (V,E) be the following directed graph. a. 1. Draw the reverse graph G of G. 2. Run DFS on G to obtain a post number for each vertex. Assume that in the adjacency list representation of G, vertices are stored alphabetically, and in the list for each vertex, its adjacent vertices are also sorted alphabetically. In other words, the DFS algorithm needs to examine all vertices alphabetically, and when it traverses the adjacent vertices...
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
Recall the definition of the degree of a vertex in a graph. a) Suppose a graph has 7 vertices, each of degree 2 or 3. Is the graph necessarily connected ? b) Now the graph has 7 vertices, each degree 3 or 4. Is it necessarily connected? My professor gave an example in class. He said triangle and a square are graph which are not connected yet each vertex has degree 2. (Paul Zeitz, The Art and Craft of Problem...