public static void Main(string[] args) { Console.WriteLine("Creating Binary Tree ... !"); var root = BinaryTreeHelper.InitializeBinaryTreeV2(); var coll = LevelTraversal(root); var inverted = Invert(root); var coll2 = LevelTraversal(inverted); bool isSymmetric = true; for (int i = 0; i < coll.Count; i++) { if (coll[i] != coll2[i]) { isSymmetric = false; break; } } Console.WriteLine(isSymmetric); Console.WriteLine("Trying another approach !"); Console.WriteLine("Creating Binary Tree ... !"); root = BinaryTreeHelper.InitializeBinaryTreeV2(); Console.WriteLine(IsSymmetricAnother(root)); }
static void Main(string[] args) { Console.WriteLine("Creating Binary Tree ... !"); var root = BinaryTreeHelper.InitializeBinaryTreeV2(); Console.WriteLine("Min Depth : " + Minimum(root, root)); }
static void Main(string[] args) { Console.WriteLine("Creating Binary Tree ... !"); var root = BinaryTreeHelper.InitializeBinaryTree(); Console.WriteLine("Preorder Recursive ... !"); PreOrder(root); Console.WriteLine(); Console.WriteLine("Preorder Iterative ... !"); PreOrderIterative(root); Console.WriteLine(); Console.WriteLine("Inorder Recursive ... !"); InOrder(root); Console.WriteLine(); Console.WriteLine("Inorder Iterative ... !"); InOrderIterative(root); Console.WriteLine(); Console.WriteLine("Postorder Recursive ... !"); PostOrder(root); Console.WriteLine(); Console.WriteLine("Postorder Iterative ... !"); PostOrderIterative(root); Console.WriteLine(); }
static void Main(string[] args) { Console.WriteLine("Creating Binary Tree ... !"); var root = BinaryTreeHelper.InitializeBinaryTreeV2(); Console.WriteLine("Diameter : " + Diameter(root)); }
static void Main(string[] args) { Console.WriteLine("Creating Binary Tree ... !"); var root = BinaryTreeHelper.InitializeBinaryTreeV3(); Console.WriteLine(Eval(root)); }
static void Main(string[] args) { Console.WriteLine("Creating Binary Tree ... !"); var root = BinaryTreeHelper.InitializeBinaryTreeV2(); Console.WriteLine("Calculating height ... !"); Console.WriteLine(Height(root)); }
static void Main(string[] args) { Console.WriteLine("Creating Binary Tree ... !"); var root = BinaryTreeHelper.InitializeBinaryTreeV2(); LevelOrderDisplay(root); root = Remove(root); LevelOrderDisplay(root); InOrder(root); }
static void Main(string[] args) { Console.WriteLine("Creating Binary Tree ... !"); var root = BinaryTreeHelper.InitializeBinaryTreeV2(); Console.WriteLine("Level Traversal ... !"); LevelTraversal(root); Console.WriteLine(); LevelOrderDisplay(root); Console.WriteLine(); }
static void Main(string[] args) { Console.WriteLine("Creating Binary Tree ... !"); var root = BinaryTreeHelper.InitializeBinaryTreeV2(); Console.WriteLine("Level Order Display"); LevelOrderDisplay(root); Console.WriteLine("Nodes at ODD level, root treated as level 1"); Odd(root); }
static void Main(string[] args) { Console.WriteLine("Creating Binary Tree ... !"); var root = BinaryTreeHelper.InitializeBinaryTree(); Console.WriteLine("Inorder Recursive ... !"); InOrder(root); Console.WriteLine(); root = Invert(root); Console.WriteLine("Inorder Recursive after revert... !"); InOrder(root); Console.WriteLine(); }
static void Main(string[] args) { Console.WriteLine("Creating Binary Tree ... !"); var root = BinaryTreeHelper.InitializeBinaryTreeV2(); LevelOrderDisplay(root); int k = 2; var nodes = KthLevel(root, k); Console.WriteLine("Nodes at level {0} are :-", k); foreach (var item in nodes) { Console.Write(item.Value + " "); } Console.WriteLine(); }
static void Main(string[] args) { //https://www.udemy.com/course/cpp-data-structures-algorithms-prateek-narang/learn/quiz/5293164#overview Console.WriteLine("Creating Binary Tree ... !"); var root = BinaryTreeHelper.InitializeBinaryTreeV2(); var targetSum = 22; List <int> temp = new List <int>(); TargetSum(root, targetSum, temp, 0); foreach (var outer in output) { foreach (var inner in outer) { Console.Write(inner + " "); } Console.WriteLine(); } }
static void Main(string[] args) { Console.WriteLine("Creating Binary Tree ... !"); var root = BinaryTreeHelper.InitializeBinaryTree(); Console.WriteLine("Counting nodes ... !"); int count = Count(root); Console.WriteLine("Total nodes = {0}", count); int nodesHavingBothChildren = CountNodesHavingBothChildren(root); Console.WriteLine("Total nodes having both children = {0}", nodesHavingBothChildren); int leafNodes = CountLeafNodes(root); Console.WriteLine("Leaf nodes = {0}", leafNodes); int leftChildNodes = CountNodesHavingONLYLeftChild(root); Console.WriteLine("Nodes with ONLY left child = {0}", leftChildNodes); int height = Depth(root); Console.WriteLine("Depth of Tree = {0}", height); }