For simplicity, I will represent theta with 'O'
Number of vertices = n
Number of edges = m
Now for the first for loop
for each vertex i: ---> O(n)
i.indegrees = 0 ---> O(1)
and for the second for loop
for each vertex i: ----> O(n)
for each neighbor j of i: ----> O(2m)
j,indegree = j.indegree + 1 ----> O(1)
Why O(2m) ?
It's because we will traverse each edge twice. Let's say there are
two nodes (- Node1 and Node2) and one edge (Edge1-2).
For i = Node1
edge = Edge1-2
For i = Node2
edge = Edge2-1
As you can see we traverse 2 nodes once and one edge twice(one for
each side of the node connected by the edge)
Thus for the first for loop ---> O(n), and for the second for loop ---> O(n*2m) = O(2nm) = O(nm)
Finally ---> O(n + nm) = O(nm) since nm >>> n
5. The in-degree of a vertex in a directed graph is the number of edges directed...
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...
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,......
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...
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...
Bounds on the number of edges in a graph. (a) Let G be an undirected graph with n vertices. Let Δ(G) be the maximum degree of any vertex in G, δ(G) be the minimum degree of any vertex in G, and m be the number of edges in G. Prove that δ(G)n2≤m≤Δ(G)n2
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?
Let G (V, E) be a directed graph with n vertices and m edges. It is known that in dfsTrace of G the function dfs is called n times, once for each vertex It is also seen that dfs contains a loop whose body gets executed while visiting v once for each vertex w adjacent to v; that is the body gets executed once for each edge (v, w). In the worst case there are n adjacent vertices. What do...
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...
For each section, is it TRUE or FALSE? a) Every DAG is a Directed Forest. b) Every Directed Forest is a DAG. c) In a Directed Tree, there is a path from every vertex to every other vertex. d) Suppose that you search a Directed Graph using DFS from all unvisited vertices, coloring edges red if they go between vertex v and an outgoing neighbor of v that you visit for the first time from v. Then the red edges...
Discrete Mathematics 6: A: Draw a graph with 5 vertices and the requisite number of edges to show that if four of the vertices have degree 2, it would be impossible for the 5 vertex to have degree 1. Repetition of edges is not permitted. (There may not be two different bridges connecting the same pair of vertices.) B: Draw a graph with 4 vertices and determine the largest number of edges the graph can have, assuming repetition of edges...