# Handshaking Lemma and Interesting Tree Properties -DSA

In this tutorial, we will learn about Handshaking Lemma and some interesting tree properties in DSA.

What is the Handshaking Lemma, exactly?

The handshake lemma is about the undirected graph. In each finite undirected network, the number of vertices with odd degrees is always even. The degree sum formula is where the handshaking lemma comes from (It is also often called the handshaking lemma).

How can the Handshaking Lemma help with Tree Data Structure?

The Handshaking lemma can be used to demonstrate the following amazing facts.

1) In a binary tree, the number of leaf nodes is always one more than the number of nodes with two offspring.

L = T + 1

L is the quantity of leaf nodes.

T denotes the number of internal nodes having two children.

Proof:

Let T denote the number of nodes with two children. Proof is classified into three types.

Case 1: Because there is just one node, the connection T = 0 L = 1 holds.

Case 2: The root has two children, indicating that the degree of root is two.

Case 3: The root has one child, hence the degree of the root is one.

As a result, T = L-1 is obtained in all three cases. Let us look at another interesting characteristic.

2) The following property holds true regardless of whether a node has 0 children or k children in a k-ary tree.

L = (k - 1)*I + 1, where L is the number of leaf nodes.

I denotes the number of internal nodes.

Proof is classified into two types.

Case 1 (Root is a Leaf): The tree has only one node. For a single node, the preceding expression holds valid because L = 1, I = 0.

Case 2 (Root is Internal Node): The root is always an internal node in trees with more than one node. For this scenario, the Handshaking Lemma can be used to verify the above expression. An undirected acyclic graph is a tree.

The total number of edges in a tree is equal to the number of nodes minus one, i.e., |E| = L + I - 1.

All internal nodes in the specified type of tree have degree k + 1 aside from the root. The root's degree is k. All of the leaves have a degree of one. The Handshaking lemma yields the following connection when applied to such trees.

So now that the aforementioned property has been demonstrated using the Handshaking Lemma.

### Feedback   