Examveda

What would be the time complexity of the following function which adds an edge between two vertices i and j, with some weight 'weigh' to the graph having V vertices?
vector<int> adjacent[15] ;
vector<int> weight[15]; 
 
void addEdge(int i,int j,int weigh) 
{	 
	adjacent[a].push_back(i); 
	adjacent[b].push_back(j); 
	weight[a].push_back(weigh); 
	weight[b].push_back(weigh); 
}

A. O(1)

B. O(V)

C. O(V*V)

D. O(log V)

Answer: Option A


This Question Belongs to Data Structure >> Graphs

Join The Discussion

Related Questions on Graphs

What is a cycle in a graph?

A. A path that starts and ends at the same vertex with no other repetitions.

B. A path that includes all vertices exactly once.

C. A path with no edges.

D. A complete traversal of all vertices.