151617181920212223
import adt.tree.TreeNode; public class Q014_Check_for_Children_Sum_Property_in_a_Binary_Tree { public static void main(String[] args) { TreeNode root = Tree.tree2(); boolean res = isSumProperty(root); System.out.println(res); }
222324252627282930
import adt.tree.TreeNode; public class Q059_Iterative_Method_to_find_Height_of_Binary_Tree { public static void main(String[] args) { TreeNode root = Tree.tree1(); int res = treeHeight(root); System.out.println(res); }
3940414243444546474849
queue.add(null); int height = 0; while (!queue.isEmpty()) { TreeNode node = queue.poll(); if (node != null) { if (node.left != null) { queue.add(node.left); }
2021222324252627
import adt.tree.TreeNode; public class Q013_Level_order_traversal_in_spiral_form { public static void main(String[] args) { TreeNode root = Tree.tree1(); zigzagPrint(root); }
3738394041424344454647
boolean leftToRight = true; curr.push(root); while (!curr.isEmpty()) { TreeNode node = curr.pop(); System.out.format("%d ", node.val); if (leftToRight) { if (node.left != null) { next.push(node.left);
131415161718192021
import adt.tree.TreeNode; public class Q010_Find_the_node_with_minimum_value_in_a_Binary_Search_Tree { public static void main(String[] args) { TreeNode root = Tree.bst2(); int min = findMin(root); System.out.println(min); }
5253545556575859
public class Q044_Construct_Special_Binary_Tree_from_given_Inorder_traversal { public static void main(String[] args) { int[] arr = {1, 5, 10, 40, 30, 15, 28, 20}; TreeNode root = buildTree(arr, 0, arr.length - 1); root.print(); }
6970717273747576777879
if (arr[i] > arr[max_index]) { max_index = i; } } TreeNode root = new TreeNode(arr[max_index]); root.left = buildTree(arr, lo, max_index - 1); root.right = buildTree(arr, max_index + 1, hi); return root;
2223242526272829
import adt.tree.TreeNode; public class Q056_Reverse_Level_Order_Traversal { public static void main(String[] args) { TreeNode root = Tree.tree1(); reverseLevelOrder(root); }
queue.add(root); Stack<Integer> stack = new Stack<Integer>(); while (!queue.isEmpty()) { TreeNode node = queue.poll(); stack.push(node.val); if (node.right != null) { queue.add(node.right); }