Tree Practice Problems in C/C++
The following is the list of C/C++ programs based on the level of difficulty:
Easy
- Write a Program to Calculate Size of a Tree | Recursion
- Find the Node with Minimum Value in a Binary Search Tree
- Program to Determine if Given Two Trees are Identical or Not
- Find the Maximum Depth or Height of Given Binary Tree
- Print Nodes at K Distance from Root
- Program to Count Leaf Nodes in a Binary Tree
- Convert a Binary Tree into its Mirror Tree
- Given a Binary Tree, Print Out All of its Root-to-leaf Paths One per Line.
- Lowest Common Ancestor in a Binary Search Tree.
- Check for Children Sum Property in a Binary Tree
Medium
- Construct Full Binary Tree Using its Preorder Traversal and Preorder Traversal of its Mirror Tree
- Construct Tree from Given Inorder and Preorder Traversals
- A Program to Check if a Binary Tree is BST Or Not
- Convert an Arbitrary Binary Tree to a Tree that Holds Children Sum Property
- Diameter of a Binary Tree
- How to Determine if a Binary Tree is Height-balanced?
- Inorder Tree Traversal without Recursion
- Root to Leaf Path Sum Equal to a Given Number
- Find K-th Smallest Element in BST (Order Statistics in BST)
- Check if a Given Binary Tree is Sumtree
Hard
- Inorder Tree Traversal without Recursion and Without Stack!
- Print Left View of a Binary Tree
- Print a Binary Tree in Vertical Order | Set 1
- Print All Nodes at Distance K from a Given Node
- Sorted Linked List to Balanced BST
- Connect Nodes at Same Level Using Constant Extra Space
- Find a Pair with Given Sum in a Balanced BST
- Maximum Sub-tree Sum in a Binary Tree Such that the Sub-tree is also a BST
- Merge Two Bsts with Limited Extra Space
- Maximum Path Sum in a Binary Tree
Tree C/C++ Programs
Trees are hierarchical data structures that contain nodes connected by edges. They are recursive in nature, which means that they are made up of smaller instances of themselves. Various types such as binary tree, trie, etc. have different characteristics to make them suitable for different applications such as storing sorted data, dictionaries, routing tables, etc.
In this article, we will discuss some top C/C++ practice problems on the tree data structure.
Prerequisite: Tree Data Structure