Esempio n. 1
0
        public void ListOfDepthsAlgo_WhenRootIsNotNull_ReturnsCorrectLists()
        {
            // Arrange
            var root      = new BinaryTreeNode <int>(10);
            var rootLeft  = new BinaryTreeNode <int>(4);
            var rootRight = new BinaryTreeNode <int>(4);

            root.Left  = rootLeft;
            root.Right = rootRight;
            var rootLeftLeft  = new BinaryTreeNode <int>(2);
            var rootLeftRight = new BinaryTreeNode <int>(8);

            rootLeft.Left  = rootLeftLeft;
            rootLeft.Right = rootLeftRight;
            var rootRightRight = new BinaryTreeNode <int>(20);

            rootRight.Right = rootRightRight;

            // Act
            var results = ListOfDepths <int> .ListOfDepthsAlgo(root);

            // Assert
            results.Count.Should().Be(3);
            results[0].Count.Should().Be(1);
            results[1].Count.Should().Be(2);
            results[2].Count.Should().Be(3);
        }
Esempio n. 2
0
        public void ListOfDepthsAlgo_WhenRootIsNull_ReturnsEmptyLists()
        {
            // Arrange & Act
            var results = ListOfDepths <int> .ListOfDepthsAlgo(null);

            // Assert
            results.Count.Should().Be(0);
        }
        public void RunTest01()
        {
            ListOfDepths test   = new ListOfDepths(tree);
            var          result = test.Run();

            Assert.IsTrue(result.Count == 3);
            Assert.IsTrue(result[0].Count == 1);
            Assert.IsTrue(result[1].Count == 2);
            Assert.IsTrue(result[2].Count == 4);
        }
Esempio n. 4
0
        public void ListOfDepthsTest()
        {
            var inputOne  = TreeNode.BuildTreeOne();
            var resultOne = ListOfDepths.Run(inputOne);

            Assert.Equal(5, resultOne[0].Value);
            Assert.Equal(3, resultOne[1].Value);
            Assert.Equal(7, resultOne[1].Next.Value);
            Assert.Equal(1, resultOne[2].Value);
            Assert.Equal(6, resultOne[2].Next.Value);
            Assert.Equal(3, resultOne.Count);


            var inputTwo  = TreeNode.BuildTreeTwo();
            var resultTwo = ListOfDepths.Run(inputTwo);

            Assert.Equal(3, resultTwo[0].Value);
            Assert.Equal(6, resultTwo[1].Value);
            Assert.Equal(5, resultTwo[2].Value);
            Assert.Equal(7, resultTwo[2].Next.Value);
            Assert.Equal(3, resultTwo.Count);
        }
Esempio n. 5
0
        public void ListOfDepthsBFSTest(TreeNode <int> root, List <LinkedList <TreeNode <int> > > expectedLinkedList)
        {
            List <LinkedList <TreeNode <int> > > result = ListOfDepths <int> .createLevelLinkedlistBFS(root);

            Assert.Equal(expectedLinkedList, result);
        }
        static void Main(string[] args)
        {
            //NUmberTriangle();
            //TopologicalSort.TopologicalSortInvoker();

            //DFS
            //DFS.GetDfs(1);

            //ActivitySelction.GetMostNumberOfActivities();
            //ActivitySelction.GetLeastChangeInLeastCoins();

            //DynamicsProgramming.SelectItemsForMaxProfit();

            //BubbleSort.BubbleSortFunc();

            //MergeSort.MergeSortFunc();

            //InsertionSort.InsertionSortFunc();

            //QuickSort.QuickSortFunc();

            //BinarySearchTree.CreateBST();

            //SinglyLinkedList.Create();
            //DoublyLinkedList.Create();
            //CircularLinkedList.Create();

            //Arrays.FindTripleToGetGivenSum();

            //Arrays.TargetSumUsingSubsetOfElements();

            //Heap.BuildHeap();

            //Console.WriteLine((new KthLargestElementInStream(3, new int[] { 3,2,3,1,2,4,5,5,6 })).KthLargest);

            //int n = UglyNumbers.NthUglyNumber(1352);

            //TopKFrequentElements.TopKFrequent(new int[] { 1,1,1,2,2,2,3,3,3}, 3);

            //LongestSubString.Test();

            //ReverseInteger.Reverse(1534236469);

            //PalindromNumber.IsPolidrom(121);

            //LongestCommonPrefixClass.LongestCommonPrefix(new string[] { "abc", "abd", "abcef" });

            //ValidaParanthesis.IsValid("([{}])");

            //RemoveDuplicatesFromSortedArray.RemoveDuplicates(new int[] { 1, 1, 1, 2, 2, 2, 3, 3, 3 });

            //MaximumSubArraySum.MaxSubArray(new int[] { 1, -1, 1, -2, 2, -2, 3, -3, 3 });

            //MaximumSubArraySum.MaxSumUsingDivideAndConquer(new int[] { -2, 1, -3, 4, -1, 2, 1, -5, 4 });

            //ClimbingStairs.ClimbStairs(10);

            //SymmetricTree.CheckSymmetricity();

            //SortedArrayToBSTClass.SortedArrayToBST(new int[] { -10, -3, 0, 5, 9 });

            //PascalsTriangle.Generate(5);

            //BestTimeToBuyAndSellStocks.MaxProfit2(new int[]{ 1, 2, 4, 2, 5, 7, 2, 4, 9, 0});

            //SingleNumberClass.SingleNumber(new int[] { 4, 1, 2, 1, 2});

            //ReverseBits.ReverseBitsWithShift(21);
            //LinkedListProblems.Palindrome.TestIsPalindrome();

            //AddTwoNumberClass obj = new AddTwoNumberClass();
            //ListNode l1 = new ListNode(2);
            //l1.next = new ListNode(4);
            //l1.next.next = new ListNode(9);

            //ListNode l2 = new ListNode(5);
            //l2.next = new ListNode(6);
            //obj.AddTwoNumbers(l1,l2); ;

            //LongestPalidromicSubString.LongestPalindrome("babad");
            //LongestPalidromicSubString.LongestPalindrome("aaaabbaa");
            //FindFruitCombos.TestWinPrize();
            //ContactsClass.Test();
            //LargestItemAssociation.Test();

            //LevelOrderTraversal.Test();

            //GraphBFS.Test();

            //MaxLengthzofPaitChain.FindLongestChain(new int[][]{
            //    new int[]{ 5,24},
            //    new int[] {39,40},
            //    new int[] { 15,28},
            //    new int[] { 27,41},
            //    new int[]{ 50,90} });

            //LongestCommonSubsequenceClass.LongestCommonSubsequence("abcbcba", "abcba");
            //LongestIncreasingSubsequence.Test();

            //ReverseLinkedListInGroups.Test();
            //CountTriplets.Test();

            //ContiguousSubArraySum.Test();

            //ReArrangeElementsAlt.Test();

            //Count7sUsingRecursion.Test();

            //NumberPermutations.Test();

            //CombinationalSum.Test();
            //SubsetsClass.Test();

            //WordSearch.Test();

            //GroupAnagramsClass.Test();

            //GraphDFS.Test();

            //DetectCycleDFS.Test();

            //DijstraShortestpath.Test();

            //DijkstraShortestPathAdjList.Test();

            //ZerosAndOnesSegregation.Test();

            //MergeTwoSortedLists.Test();

            //MinCostToDest.Test();

            //MinPathSumClass.Test();

            //BinaryTreeToLinkedList.Test();

            //WordBreakClass.Test();

            //WordBreak2.Test();

            //LongestPalidromicSubString.Test();

            //RegexMatching.Test();

            //UniquePaths2.Test();

            //UniquePaths3.Test();

            //Subsets2.Test();

            //CombinationalSum2.Test();

            //PalindromePartitioning.Test();

            //LongestIncreasingSubSequence.Test();

            //TrueBoardGame.Test();
            //FindIfThereExistsAPath.Test();

            //MinimalBST.Test();

            //CheckBalanced.Test();

            ListOfDepths.Test();

            Console.Read();
        }