GeeksforGeeks

A computer science portal for geeks
Register  |  Login

Browsing the topic Trees

Given a Binary Tree, write a function that returns the size of the largest subtree which is also a Binary Search Tree (BST). If the complete Binary Tree is BST, then return the size of whole tree.

Read More »

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 left and right sub trees in the original tree. The values of leaf nodes are changed to 0.

Read More »

Given a Binary Tree where each node has following structure, write a function to populate next pointer for all nodes.

Read More »

Given a sorted array. Write a function that creates a Balanced Binary Search Tree using array elements.

Read More »

Write a function to connect all the adjacent nodes at the same level in a binary tree. Structure of the given Binary Tree node is like following.

Read More »

Write a function to connect all the adjacent nodes at the same level in a binary tree. Structure of the given Binary Tree node is like following.

Read More »

In the previous post on trie we have described how to insert and search a node in trie. Here is an algorithm how to delete a node from trie.

Read More »

Trie is an efficient information retrieval data structure. Using trie, search complexities can be brought to optimal limit (key length).

Read More »

Given two binary trees, check if the first tree is subtree of the second one.

Read More »

Let us solve the “fake coin” puzzle using decision trees. There are two variants of the puzzle.

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 a node is equal to sum of the nodes present in its left subtree and right subtree.

Read More »

Given a team of N players. How many minimum games are required to find second best player?

Read More »

Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Print all the keys of tree in range k1 to k2. i.e. print all x such that k1

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.

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 key is 3, then your function should return 1.

Read More »

Given root of binary search tree and K as input, find K-th smallest element in BST. Related Post

Read More »

In Binary Tree, Inorder successor of a node is the next node in Inorder traversal of the Binary Tree. Inorder Successor is NULL for the last node in Inoorder traversal.

Read More »

Difficulty Level: Rookie Why Tree? Unlike Array and Linked List, which are linear data structures, tree is hierarchical (or non-linear) data structure.

Read More »

Given an array that stores a complete Binary Search Tree, write a function that efficiently prints the given array in ascending order.

Read More »

Given a root of a tree, and an integer k. Print all the nodes which are at k distance from root.

Read More »

Question: Given a binary tree, find out if the tree can be folded or not. A tree can be folded if left and right subtrees of the tree are structure wise mirror image of each other. An empty tree is considered as foldable.

Read More »

Given a binary tree, write a function to get the maximum width of the given tree. Width of a tree is maximum of widths of all levels.

Read More »

Write a program that converts a given tree to its Double tree. To create Double tree of the given tree, create a new duplicate for each node, and insert the duplicate as the left child of the original node.

Read More »

For the below example tree, all root-to-leaf paths are:

Read More »

Let us consider the below traversals: Inorder sequence: D B E A F C Preorder sequence: A B D E C F

Read More »
Tweet