Question

In: Advanced Math

Consider an unweighted, undirected graph G = <V, E>. The neighbourhood of a node v ∈...

Consider an unweighted, undirected graph G = <V, E>. The neighbourhood of a node v ∈ 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, assuming that the input is the graph, G, represented using an adjacency list. Each item i in the list that you generate will correspond to the correct value for the neighbourhood degree of node vi. Your algorithm should be presented in unambiguous pseudocode. Your algorithm should have a time complexity value O(V +E).

(b) If an adjacency matrix was used to represent the graph instead of an adjacency list, what is the new value for the time complexity? Justify your answer by explicitly referring to the changes that would be necessary to your algorithm from part (a).

Solutions

Expert Solution

SOLUTION

A)

function G)

//n is number of vertices or equal to V

deg [n]

//calculate degree of each vertex

for i=0 to i=n-1

deg [i] = len (adjacency_list [i])

neighbourhood_degree[n]

//for each vertex calculate it neighbourhood degree

for i=0 to n-1

//neighbourhood [i] is sum of degree of all vertices in adjacency_list of i

for j=0 to len (adjacency_list [i]-1)

neighbour_degree[i]+ = degree [adjacency_list [i] [j] ]

return neighbourhood_degree

The time complexity of algorithm is O (V+E)

B)

The time complexity of this part will be O(V2)

pseudo code

function neighbourhood_degree (G)

degree [n]

//calculate degree of each vertex

//in adjacency matrix one has to traverse each vertex and check if it has edge with that edge or not

//this operation take n2

for i=0 to n-1

for j=0 to n-1

if adjacency_matrix [i] [j] is non zero

degree [i]+=1

neighbourhood_degree [n]

//calculate neighbourhood_degree of each vertex

for i=0 to n-1

for j=0 to j=n-1

//if there is a edge between i and j

//add the degree [j] to neighbourhood of i

if adjacency_matrix [i] [j] is non zero

neighbourhood_degree [i]+=degree [j]

return neighbourhood_degree


Related Solutions

You are given an undirected graph G = ( V, E ) in which the edge...
You are given an undirected graph G = ( V, E ) in which the edge weights are highly restricted. In particular, each edge has a positive integer weight from 1 to W, where W is a constant (independent of the number of edges or vertices). Show that it is possible to compute the single-source shortest paths in such a graph in O(E+V) time.
Given an undirected graph G=(V, E) with weights and a vertex , we ask for a...
Given an undirected graph G=(V, E) with weights and a vertex , we ask for a minimum weight spanning tree in G where is not a leaf (a leaf node has degree one). Can you solve this problem in polynomial time? Please write the proof.
Prove or disprove: If G = (V; E) is an undirected graph where every vertex has...
Prove or disprove: If G = (V; E) is an undirected graph where every vertex has degree at least 4 and u is in V , then there are at least 64 distinct paths in G that start at u.
Given an undirected graph G = (V,E), consisting of n vertices and m edges, with each...
Given an undirected graph G = (V,E), consisting of n vertices and m edges, with each edge labeled from the set {0,1}. Describe and analyze the worst-case time complexity of an efficient algorithm to find any cycle consisting of edges whose labels alternate 0,1.
Problem 2. Consider a graph G = (V,E) where |V|=n. 2(a) What is the total number...
Problem 2. Consider a graph G = (V,E) where |V|=n. 2(a) What is the total number of possible paths of length k ≥ 0 in G from a given starting vertex s and ending vertex t? Hint: a path of length k is a sequence of k + 1 vertices without duplicates. 2(b) What is the total number of possible paths of any length in G from a given starting vertex s and ending vertex t? 2(c) What is the...
Design a linear-time algorithm which, given an undirected graph G and a particular edge e in...
Design a linear-time algorithm which, given an undirected graph G and a particular edge e in it, determines whether G has a cycle containing e. Your algorithm should also return the length (number of edges) of the shortest cycle containing e, if one exists. Just give the algorithm, no proofs are necessary. Hint: you can use BFS to solve this.
A maximal plane graph is a plane graph G = (V, E) with n ≥ 3...
A maximal plane graph is a plane graph G = (V, E) with n ≥ 3 vertices such that if we join any two non-adjacent vertices in G, we obtain a non-plane graph. a) Draw a maximal plane graphs on six vertices. b) Show that a maximal plane graph on n points has 3n − 6 edges and 2n − 4 faces. c) A triangulation of an n-gon is a plane graph whose infinite face boundary is a convex n-gon...
Let G = (V, E) be a directed graph, with source s ∈ V, sink t...
Let G = (V, E) be a directed graph, with source s ∈ V, sink t ∈ V, and nonnegative edge capacities {ce}. Give a polynomial-time algorithm to decide whether G has a unique minimum s-t cut (i.e., an s-t of capacity strictly less than that of all other s-t cuts).
Determine, for a given graph G =V,E and a positive integer m ≤ |V |, whether...
Determine, for a given graph G =V,E and a positive integer m ≤ |V |, whether G contains a clique of size m or more. (A clique of size k in a graph is its complete subgraph of k vertices.) Determine, for a given graph G = V,E and a positive integer m ≤ |V |, whether there is a vertex cover of size m or less for G. (A vertex cover of size k for a graph G =...
Problem 8. A bipartite graph G = (V,E) is a graph whose vertices can be partitioned...
Problem 8. A bipartite graph G = (V,E) is a graph whose vertices can be partitioned into two (disjoint) sets V1 and V2, such that every edge joins a vertex in V1 with a vertex in V2. This means no edges are within V1 or V2 (or symbolically: ∀u, v ∈ V1, {u,v} ∉ E and ∀u,v ∈ V2, {u,v} ∉ E). 8(a) Show that the complete graph K2 is a bipartite graph. 8(b) Prove that no complete graph Kn,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT