Lowest common ancestor of a binary tree

Here we are finding the lowest common ancestor of a binary tree. Here if the root2 is in between data 1 and data2 then we found
out ancestor.

Result: 30

Lowest Common Ancestor of a Binary Search Tree

Today we are finding the lowest common ancestor of a binary search tree. Here if the root data is in between data 1 and data 2 then we found out our lowest common ancestor.

Below is the code:

Output:
The common ancestor is 30
The common ancestor is 8
The common ancestor is 30

Spiral Order In BinaryTree

Today we will cover Tree Traversal Spiral Order topic. We are using 2 stack in this. First we push value in stack 1 and then it’s child in stack 2. Then doing the same steps till every node is covered.

Below is the running code:

TreeNode.java

Output:

4
5
6
7
8
10
—————Spiral Order In BinaryTree Printing————-
10
5
6
4
8
7