Binary Tree Standard Questions

Ameya Mathur
4 min readNov 8, 2022

--

GeeksForGeeks + LeetCode

Q1. Height of Binary Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q2. Convert to Mirror Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q3. Check if Symmetric Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q4. Diameter of Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q5. Check for Balanced Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q6. Children Sum Parent

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q7. Check for Binary Search Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q8. Convert to Mirror Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q9. Array to Binary Search Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q10. Kth Largest Element in a Binary Search Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q11. Check if SubTree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q12. Convert to Mirror Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q13. Boundary Traversal of Binary Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q14. Construct Binary Tree from Parent Array

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q15. Min distance between two given nodes of a Binary Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q16. Max sum leaf to root path in a Binary Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q17. Lowest Common Ancestor in a Binary Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q18. Sum Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q19. Level Order Traversal of Binary Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q20. Merge 2 Binary Search Trees

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q21. Invert a Binary Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q22. Range Sum of a Binary Search Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q23. Print Binary Tree Paths in a Binary Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q24. Same Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q25. Sum of left leaves in a Binary Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q26. Balanced Binary Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q27. Validate Binary Search Tree

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q28. Binary Tree Zig-Zag level order traversal

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

Q29. Path Sum III

class Solution {

int height(Node node)
{
if(node == null) return 0;

int left = height(node.left);
int right = height(node.right);

return Math.max(left, right) + 1;
}
}

--

--

Ameya Mathur
Ameya Mathur

Written by Ameya Mathur

0 Followers

A crazy Blogger and an Internet Marketer who aims to help aspiring and passionate entrepreneurs to start their own Online Successful Money Making Business.

No responses yet