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);
}
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

Join The Discussion