What would be the time complexity of the following function which adds an edge between two vertices i and j, with some w
Posted: Wed Jul 13, 2022 7:44 pm
vector<int> adjacent[15] ;
vector<int> weight[15];
void addEdge(int i,int j,int weigh)
{
adjacent[a].push_back(i);
adjacent.push_back(j);
weight[a].push_back(weigh);
weight.push_back(weigh);
}
a) O(1)
b) O(V)
c) O(V*V)
d) O(log V)
vector<int> weight[15];
void addEdge(int i,int j,int weigh)
{
adjacent[a].push_back(i);
adjacent.push_back(j);
weight[a].push_back(weigh);
weight.push_back(weigh);
}
a) O(1)
b) O(V)
c) O(V*V)
d) O(log V)