Question
Calculate time complexity in calculating Outdegree and Indegree of Adjacency list.
My Approach/Doubt
Let Adj[] be an array of size V where V=No. of vertices in a directed graph for representing adjacency list.
I know that ,
Outdegree of vertex u (u belongs to V) is actually the length of Adj[u]
and
Indegree of vertex u (u belongs to V) is actually the count of u in list Adj.
In both the cases , i think the time complexity should be theta (V*E)
Where V=no. of vertices
E=no. of edges
because for calculating outdegree,we scan all vertices and under each vertices we scan all the edges of that vertices.
Then why it is Thrta (V+E)
Please correct me where i am wrong?
Thanks!