Suppose we have a list of degrees of some vertices. We have to check whether it is forming graph or tree.
So, if the input is like deg = [2,2,3,1,1,1], then the output will be Tree
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(deg): vert = len(deg) deg_sum = sum(deg) if 2*(vert-1) == deg_sum: return 'Tree' return 'Graph' deg = [2,2,3,1,1,1] print(solve(deg))
[2,2,3,1,1,1]
Tree