Count the degrees
Warm-up · Trace the algorithm · about 4 min
The counters start at 0. The edges are read in the order 0-1, 1-2, 0-3, 1-3, 3-4, 2-4, 4-5, and each edge adds 1 at both of its ends.
Answer each question before the step plays.
Example 1
Input:
{"n":6,"edges":[[0,1],[1,2],[0,3],[1,3],[3,4],[2,4],[4,5]],"directed":false,"positions":[[0,0],[1.5,0],[3,0],[0.75,1.4],[2.25,1.4],[3.75,1.4]]}
Output:
[2,3,2,3,3,1]
Final degree of each vertex 0 to 5.
Constraints
- The trace uses the graph shown
Learn the idea first: Graphs: vertices, edges, directed, weighted, degree, paths, a visual lesson.
More Graphs: vertices, edges, directed, weighted, degree, paths problems
- Path or cycle? Standard
- Degree of every vertex Standard
- Is this sequence a path? Standard
- In-degree and out-degree Standard
- The handshake lemma Challenge