Given a directed graph, the task is to count the in and out degree of each vertex of the graph.
Input: Output: Vertex In Out 0 1 2 1 2 1 2 2 3 3 2 2 4 2 2 5 2 2 6 2 1
Approach: Traverse adjacency list for every vertex, if size of the adjacency list of vertex i is x then the out degree for i = x and increment the in degree of every vertex that has an incoming edge from i. Repeat the steps for every vertex and print the in and out degrees for all the vertices in the end.
Below is the implementation of the above approach:
Vertex In Out 0 1 2 1 2 1 2 2 3 3 2 2 4 2 2 5 2 2 6 2 1
- Construct a graph from given degrees of all vertices
- Check whether given degrees of vertices represent a Graph or Tree
- Number of trees whose sum of degrees of all the vertices is L
- Find K vertices in the graph which are connected to at least one of remaining vertices
- Detect cycle in the graph using degrees of nodes of graph
- Sum of degrees of all nodes of a undirected graph
- Articulation Points (or Cut Vertices) in a Graph
- Number of Simple Graph with N Vertices and M Edges
- Minimum number of edges between two vertices of a graph using DFS
- Maximum and minimum isolated vertices in a graph
- Minimum number of edges between two vertices of a Graph
- Find if there is a path between two vertices in a directed graph
- Find two disjoint good sets of vertices in a given graph
- Largest subset of Graph vertices with edges of 2 or more colors
- Calculate number of nodes between two vertices in an acyclic Graph by Disjoint Union method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.