Handshaking Lemma and Interesting Tree Properties -DSA28 Aug 2024 | 3 min read 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. |
In this article, we will explore AVL tree implementation by using Golang. An AVL tree is a type of self-balancing binary search tree which keeps the tree balanced by keeping the variation between both the heights of the left and right subtrees to a maximum of one....
3 min read
Introduction In computer science, binary trees are a basic type of data structure that is often used to depict hierarchical relationships. Finding the absolute difference in the sums of the nodes visible from the right perspective of two binary trees is an interesting topic in binary tree...
4 min read
? The Stack is a basic data structure widely used in programming and computer science. Elements are added to and deleted from the top of the Stack according to the last-in, first-out (LIFO) principle. A priority queue or heap can efficiently implement a stack, even though they...
7 min read
Introduction For complex problems to be solved in the world of computer science and algorithms, it is essential to find effective ways to process and manipulate data. The MO algorithm, which bears the name of its developer Moshe Lewenstein, is a potent data structure query method that...
5 min read
Introduction: Given an integer array, we want to make all the elements in the array equal, and we have to provide the output with the minimum number of steps to reduce the array elements to zero. Approach 1: Using brute force approach Java Code: import java.util.Arrays; public class MakeArrayZeroBruteForce { ...
13 min read
Consider a situation in which various unique components are given as a puzzle. This array has a hidden pattern: triplets with a zero sum. The objective is to crack this protected code, locate these illusive triplets, and in a concise manner present them. The mathematical goal...
7 min read
Create a function that would reverse every t nodes in a linked list (where t is an input to the function). Example: • Input: 11->12->13->14->15->16->17->18->NULL, t = 3 Output: 13->12->11->16->15->14->18->17->NULL • Input: 11->12->13->14->15->16->17->18->NULL, t = 5 Output: 15->14->13->12->11->18->17->16->NULL Algorithm: reverse(head, t) Reverse the first...
4 min read
This article will provide an overview and Python implementation of the merge two sorted linked lists algorithm. Linked lists are fundamental data structures used in computer science and programming. They provide an efficient way to store and organize data non-contiguously. Linked lists consist of nodes containing data...
4 min read
Introduction N-Ary trees are a type of hierarchical data structure that can be used to represent hierarchical relationships in a variety of domains because their nodes can have multiple children. A strong locking and unlocking mechanism must be implemented in situations where several threads or processes must...
5 min read
? In this tutorial, we will discus about the deleting operations in singly linked list. How does a Node in a Singly Linked List get deleted? To remove a node from a linked list, we must first break the link that connects that node to the one that points...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India