Largest BST in a Binary Tree | Set 3 Method 3 (Shorter, Smarter and More Efficient) In this section, a different O(n) solution is discussed.… Read More
Category Archives: Tree
Given a Binary Tree where each node has positive and negative values. Convert this to a tree where each node contains the sum of the… Read More
Given a Binary Tree where each node has the following structure, write a function to populate the next pointer for all nodes. The next pointer… Read More
Given a sorted array. Write a function that creates a Balanced Binary Search Tree using array elements. Examples: Input: arr[] = {1, 2, 3}Output: A… Read More
Write a function to connect all the adjacent nodes at the same level in a binary tree. The structure of the given Binary Tree node… Read More
Given a Binary Tree, The task is to connect all the adjacent nodes at the same level starting from the left-most node of that level,… Read More
Given two binary trees, check if the first tree is a subtree of the second one. A subtree of a tree T is a tree… Read More
Write a function that returns true if the given Binary Tree is SumTree else false. A SumTree is a Binary Tree where the value of… Read More
A Minimum Spanning Tree (MST) is a subset of the edges of a connected, undirected graph that connects all the vertices together, without any cycles… Read More
Given two values k1 and k2 where k1 < k2 and a root pointer to a Binary Search Tree. The task is to print all… Read More
Given a Binary Tree and a key, write a function that prints all the ancestors of the key in the given binary tree. For example,… Read More
Given a Binary Tree and a key, write a function that returns level of the key. For example, consider the following tree. If the input… Read More
Applications of tree data structure What is Tree Data Structure? A tree is a type of data structure that represents a hierarchical relationship between data… Read More
Given a root of a tree, and an integer k. Print all the nodes which are at k distance from root. For example, in the below… Read More
Given a binary tree, find out if the tree can be folded or not. A tree can be folded if the left and right subtrees… Read More