those who are wondering why at some places…
First of all I want to clear whenever not specified in question by default binary tree is directed.
sum of degree of all nodes = 2 * number of edges
OR
sum of degree of all nodes = number of edges
Let’s see where to use which formula ..
Firstly ,
sum of degree of all nodes = 2 * number of edges
As you know this formula comes from graph theory and this is used whenever the neighbour of nodes is given. Like for example total no. of nodes of neighbour 2 is 10 and neighbour 1 is 11. and this formula you can apply considering binary tree as undirected because whenever neighbour is given you are counting the edges twice for each node. Let a right skewed tree of 2 nodes annotations is A(root) , B.
So, applying formula,
sum of degree of all nodes =1 (considering A) + 1 (considering 2)
that’s why 1 edge is counted twice.So, relate it with no. of edges in formula.
Now, second one
sum of degree of all nodes = number of edges
whenever the degree of nodes is given. Like for example total no. of nodes of degree 2 is 10 and degree 1 is 11. and this formula you can apply considering binary tree as directed because whenever degree is given you are counting the edges single for each node. Let a right skewed tree of 2 nodes annotations is A(root) , B.
So, applying formula,
sum of degree of all nodes =1 (considering A)
here due to directed the edge is counted only once. So, relate it with no. of edges in formula.
Hope this helps!!!!