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

Suppose the unweighted graph graph G = (V, E), represents connections between cities in a country. Salesman wants to get from city A to city P using the unweighted graph G = (V, E) of cities.
Algorithm and Data StructuresSuppose the unweighted graph graph G = (V, E), represents connections between cities in a country. Salesman wants to get from city A to city P using the unweighted graph G = (V, E) of cities.a) Explain how the salesman use BFS algorithm to get from city A to city P passing smallest number of cities. (all steps required)b) Now the salesman likes to visit city R on his way to city P. Describe an efficient algorithm...
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.
Let G(V, E,w) be a weighted undirected graph, where V is the set of vertices, E...
Let G(V, E,w) be a weighted undirected graph, where V is the set of vertices, E is the set of edges, and w : E → R + is the weight of the edges (R + is the set of real positive numbers). Suppose T(G) is the set of all minimum spanning trees of G and is non-empty. If we know that the weight function w is a injection, i.e., no two edges in G have the same weight, then:...
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.
If G = (V, E) is a graph and x ∈ V , let G \...
If G = (V, E) is a graph and x ∈ V , let G \ x be the graph whose vertex set is V \ {x} and whose edges are those edges of G that don’t contain x. Show that every connected finite graph G = (V, E) with at least two vertices has at least two vertices x1, x2 ∈ V such that G \ xi is connected.
Consider a modification to the DFS procedure such that it returns for an undirected graph G,...
Consider a modification to the DFS procedure such that it returns for an undirected graph G, the connected components of G. To do this, you will modify the DFS procedure to • maintain a counter i, initially set in 1, that counts how many connected components we found so far; and • on each vertex v ∈ G.V maintain an attribute component indicating to which connected component number v belong to. That is, when DFS terminates, v.component indicates the component...
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT