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
- Articulation Points (or Cut Vertices) in a Graph
- 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
- 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
- Finding minimum vertex cover size of a graph using binary search
- Graph implementation using STL for competitive programming | Set 2 (Weighted graph)
- Count all possible paths between two vertices
- Longest path between any pair of vertices
- Minimum Operations to make value of all vertices of the tree Zero
- Minimum initial vertices to traverse whole matrix with given conditions
- Find maximum number of edge disjoint paths between two vertices
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.