Showing posts with label Java_BinaryTree_coding_Question. Show all posts
Showing posts with label Java_BinaryTree_coding_Question. Show all posts

May 5, 2022

Question 67 : Count subtrees with Sum equal to target in binary tree?

 Given a binary tree and an integer. You need to find the number of subtrees having the sum of all of its nodes equal to given Integer, that is, Target sum.

Question 66 : How to print vertical sum of binary tree?

 You need to find sum of nodes which lies in same column.



Question 65 : How to do boundary traversal of binary tree.

 Write a java program to do boundary traversal of binary tree as shown in below image.



Question 64 : How to find lowest common ancestor(LCA) in binary tree.

 You need to write a program to find LCA in binary tree.



Question 63 : How to find maximum element in binary tree.

 You need to write a java program to find maximum element in binary tree.

Question 62 : How to find level of node in binary tree

Given a node, you need to find level of a node. For example : Level of node will 3 for node 70 used in Question 14.

Question 61 : How to print all paths from root to leaf in binary tree.

 You need to write a program to print all paths from root to leaf.


Question 60 : How to count leaf nodes of binary tree.

You need to write a java program to count leaf nodes of a binary tree.

The count of Leaf nodes for the binary tree used in Question 15 is 5.

Question 59 : How can you print leaf nodes of binary tree?

 Steps for counting number of leaf nodes are:

  • If node is null then return 0
  • If encounterd leaf node(i.e. node.left is null and node.right is null) then print the node.
  • Recursively visit leaf subtree and right subtree.

Question 58 : Write an algorithm to do spiral order traversal of binary tree?

 You need to write java program to do spiral level order traversal of binary tree




Question 57 : Write an algorithm to do level order traversal of binary tree?

You need to write java program to do level order traversal of binary tree. You can use queue data structure to do level order traversal.



May 3, 2022

Question : Binary Tree PostOrder traversal in java

 PostOrder traversal

In PostOrder traversal, each node is processed after subtrees traversal.In simpler words,Visit left subtree,  right subtree and then node.

Steps for PostOrder traversal are:

Question : Binary Tree InOrder traversal in java

 InOrder traversal:

In InOrder traversal, each node is processed between subtrees. In simpler words, Visit the left subtree, node, and then right subtree.

Steps for InOrder traversal are:

Question 56 : How can you traverse binary tree?

 There are three ways to traverse a binary tree

PreOrder

InOrder

PostOrder

You may also like

Kubernetes Microservices
Python AI/ML
Spring Framework Spring Boot
Core Java Java Coding Question
Maven AWS