Binary Minimum and Maximum Longest Path from Root Node
The Longest Path from Root Node
/**
Find the longest path from the root node
*/
public static int binLongestPath(Node root){
if(root != null){
int l = binLongestPath(root.left);
int r = binLongestPath(root.right);
return Math.max(l, r) + 1;
}
return 0;
}
The shortest Path from Root Node
/**
Find the shortest path from the root node
*/
public static int binShortestPath(Node root){
if(root != null){
int l = binShortestPath(root.left);
int r = binShortestPath(root.right);
return Math.min(l, r) + 1;
}
return 0;
}