Example #1
0
            public void MinimalHeightBinarySearchTreeTest4()
            {
                var nums = new[] { 1, 4, 8 };

                var tree = CreateMinimalHeightBinarySearchTree(nums);

                tree.Print();

                Assert.True(Q4P1IsBinaryTreeBalanced.IsBalanced(tree));
                Assert.AreEqual(2, Q4P1IsBinaryTreeBalanced.GetHeightOfTree(tree));
            }
Example #2
0
            public void MinimalHeightBinarySearchTreeTest5()
            {
                for (int i = 1; i < 20; i++)
                {
                    int max  = 2 << i - 1;
                    var nums = Enumerable.Range(0, max).ToArray();

                    var tree = CreateMinimalHeightBinarySearchTree(nums);

                    Assert.True(Q4P1IsBinaryTreeBalanced.IsBalanced(tree));
                    Assert.AreEqual(i + 1, Q4P1IsBinaryTreeBalanced.GetHeightOfTree(tree));
                }
            }