Challenge: Calculate the Number of Nodes in a Given Graph Level
Given a graph, calculate the number of nodes in an undirected graph level.
We'll cover the following
Problem Statement
Implement a function that returns the number of nodes at a given level of an undirected graph in C++.
Try modifying the Breadth-First Traversal algorithm to achieve this goal.
Input
An undirected graph represented as an adjacency list, a starting vertex, and the level whose number of nodes we need to find.
Output
The number of nodes returned as a simple integer.
Sample Input
Graph:
graph {0 - 1
0 - 2
1 - 3
2 - 3
3 - 5
2 - 4
}
Level: 1
Sample Output
1
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.