public void FindSubstringPerformance()
        {
            var bigString   = "1234567890*-qwertyuıopğüasdfghjklşi,<zxcvbnmöç.";
            var smallString = "34567890*-qwertyuıopğüasdfghjklşi,<zxcvbnmö";

            var stopWatch1 = Stopwatch.StartNew();

            stopWatch1.Start();
            for (int i = 0; i < 100000; i++)
            {
                RabinKarp.FindSubstring(bigString, smallString);
            }

            stopWatch1.Stop();
            var time1 = stopWatch1.ElapsedMilliseconds;

            var stopWatch2 = Stopwatch.StartNew();

            stopWatch2.Start();
            for (int i = 0; i < 100000; i++)
            {
                bigString.IndexOf(smallString);
            }

            stopWatch2.Stop();
            var time2 = stopWatch2.ElapsedMilliseconds;

            Assert.IsTrue(time1 < time2);
        }
예제 #2
0
        static void Main(string[] args)
        {
            /*
             * Sudoku.Sudoku game = new Sudoku.Sudoku();
             * game.PrintBoard();
             * Console.WriteLine("--------------");
             * if (game.SolveSudoku())
             * {
             *  game.PrintBoard();
             * }
             * Console.WriteLine("----------------");
             */



            string text    = "ABBA";
            string pattern = "BA";

            KMPAlgo stringSearch = new KMPAlgo();

            Console.WriteLine("KMP algorithm-------------------");
            Console.WriteLine(stringSearch.PatternMatch(text, pattern));
            Console.WriteLine("-------------------");

            Console.WriteLine("Rabin Karp algorithm-------------------");
            RabinKarp rabinAlgo = new RabinKarp();

            Console.WriteLine(rabinAlgo.PatternSearch(text, pattern));
            Console.WriteLine("-------------------");

            Console.Read();
        }
예제 #3
0
        public void String_RabinKarp_Test()
        {
            var algorithm = new RabinKarp();

            var index = algorithm.Search("xabcabzabc", "abc");

            Assert.AreEqual(1, index);

            index = algorithm.Search("abdcdaabxaabxcaabxaabxay", "aabxaabxcaabxaabxay");

            Assert.AreEqual(5, index);

            index = algorithm.Search("aaaabaaaaaaa", "aaaa");

            Assert.AreEqual(0, index);

            index = algorithm.Search("abcabababdefgabcd", "fga");

            Assert.AreEqual(11, index);

            index = algorithm.Search("abxabcabcaby", "abcaby");

            Assert.AreEqual(6, index);

            index = algorithm.Search("abxabcabcaby", "abx");

            Assert.AreEqual(0, index);
        }
예제 #4
0
        private static void SearchPattern(string pat, string txt)
        {
            //var pattern = pat.ToCharArray();
            //var text = txt.ToCharArray();

            var rabinKarp1 = new RabinKarp(pat);
            var offset1    = rabinKarp1.Search(txt);



            // print results
            Console.WriteLine("text:    " + txt);

            Console.Write("pattern: ");
            for (var i = 0; i < offset1; i++)
            {
                Console.Write(" ");
            }
            Console.WriteLine(pat);

            //Console.Write("pattern: ");
            //for (var i = 0; i < offset2; i++)
            //    Console.Write(" ");
            Console.WriteLine(pat);
        }
예제 #5
0
        public void Should_Throw_If_Input_Is_Null()
        {
            //arrange

            //act
            Action action = () => RabinKarp.Compute(null, null);

            //assert
            action.ShouldThrow <ArgumentNullException>();
        }
예제 #6
0
        public void Should_Check_Same_Length()
        {
            //arrange
            string text    = "abedabc";
            string pattern = "abedabc";

            //act
            var result = RabinKarp.Compute(text, pattern);

            //assert
            result.ShouldBeEquivalentTo(true);
        }
예제 #7
0
        public void Should_Check_Wrong_Length()
        {
            //arrange
            string text    = "";
            string pattern = "1";

            //act
            var result = RabinKarp.Compute(text, pattern);

            //assert
            result.ShouldBeEquivalentTo(false);
        }
예제 #8
0
        public void Should_Check_Empty_String()
        {
            //arrange
            string text    = "";
            string pattern = "";

            //act
            var result = RabinKarp.Compute(text, pattern);

            //assert
            result.ShouldBeEquivalentTo(true);
        }
예제 #9
0
        public void PreComputeHashesTest()
        {
            string testStr    = "aaaa";
            int    patternLen = 2;

            long[] H = RabinKarp.PreComputeHashes(
                testStr, patternLen, 101, 3);

            for (int i = 0; i < testStr.Length - patternLen + 1; i++)
            {
                long expectedHash = RabinKarp.PolyHash(testStr, i, patternLen, 101, 3);
                Assert.AreEqual(expectedHash, H[i]);
            }
        }
예제 #10
0
        public void PreComputeHashesTest()
        {
            string testStr    = "nbvgcfdretfyghjugfdrtyghjuiytrdsfxcvbjhytrdfgcvbnhjkuiytgfhbvnm";
            int    patternLen = 4;

            long[] H = RabinKarp.PreComputeHashes(
                testStr, patternLen, 101, 3);

            for (int i = 0; i < testStr.Length - patternLen + 1; i++)
            {
                long expectedHash =
                    HashingWithChain.PolyHash(testStr, i, patternLen, 101, 101, 3);
                Assert.AreEqual(expectedHash, H[i]);
            }
        }
예제 #11
0
        public void Test()
        {
            String text = "o fare thee well, poor devil of a Sub-Sub, whose commen- \n" + "tator I am. Thou belongest to that hopeless, sallow tribe \n"
                          + "which no wine of this world will ever warm ; and for whom \n" + "even Pale Sherry would be too rosy-strong ; but with whom \n"
                          + "one sometimes loves to sit, and feel poor-devilish, too ; and \n"
                          + "grow convivial upon tears ; and say to them bluntly with full \n" + "eyes and empty glasses, and in not altogether unpleasant \n"
                          + "sadness Give it up, Sub-Subs ! For by how much the more \n" + "pains ye take to please the world, by so much the more shall \n"
                          + "ye forever go thankless ! Would that I could clear out \n" + "Hampton Court and the Tuileries for ye ! But gulp down \n"
                          + "your tears and hie aloft to the royal-mast with your hearts ; \n" + "for your friends who have gone before are clearing out the \n"
                          + "seven-storied heavens, and making refugees of long-pampered \n" + "Gabriel, Michael, and Raphael, against your coming. Here \n"
                          + "ye strike but splintered hearts together there, ye shall \n" + "strike unsplinterable glasses! ";

            RabinKarp bm = new RabinKarp("the");

            print("found at " + bm.Search(text));
            Assert.NotEqual(-1, bm.Search(text));
        }
예제 #12
0
        public void PreComputeHashesTest()
        {
            string testStr    = "aaaa";
            int    patternLen = 2;

            long[] H = RabinKarp.PreComputeHashes(
                testStr, patternLen, 101, 3);

            long[] expectedHash = new long[testStr.Length - patternLen + 1];

            for (int i = testStr.Length - patternLen; i >= 0; i--)
            {
                expectedHash[i] =
                    HashingWithChain.PolyHash(testStr, i, patternLen, p: 101, x: 3);
            }


            CollectionAssert.AreEqual(expectedHash, H);
        }
        public void FindSubstring()
        {
            var bigString   = "1234567890*-qwertyuıopğüasdfghjklşi,<zxcvbnmöç.";
            var smallString = "klşi";
            var pos         = RabinKarp.FindSubstring(bigString, smallString);
            var posToCheck  = bigString.IndexOf(smallString);

            Assert.AreEqual(pos, posToCheck);

            bigString   = "1234567890*-qwertyuıopğüasdfghjklşi,<zxcvbnmöç.";
            smallString = "XYZ";
            pos         = RabinKarp.FindSubstring(bigString, smallString);
            posToCheck  = bigString.IndexOf(smallString);
            Assert.AreEqual(pos, posToCheck);

            bigString   = "1234567890*-qwertyuıopğüasdfghjklşi,<zxcvbnmöç.";
            smallString = "34567890*-qwertyuıopğüasdfghjklşi,<zxcvbnmö";
            pos         = RabinKarp.FindSubstring(bigString, smallString);
            posToCheck  = bigString.IndexOf(smallString);
            Assert.AreEqual(pos, posToCheck);
        }
예제 #14
0
        public void FindAllOccurrences_IndexCheck(string t, string p, int[] expectedIndices)
        {
            List <int> result = RabinKarp.FindAllOccurrences(t, p);

            Assert.AreEqual(result, new List <int>(expectedIndices));
        }
예제 #15
0
        static void Main(string[] args)
        {
            RabinKarp rkp = new RabinKarp();

            rkp.CheckPattern();

            Console.WriteLine(1 % 2);  //1
            Console.WriteLine(8 % 10); //8
            Console.WriteLine(5 % 3);  //2
            Console.WriteLine(3 % 3);  //1
            Console.WriteLine(5 / 3);  //1
            Console.WriteLine(6 / 3);  //2
            Console.WriteLine(6 / 6);  //1


            string           A   = "1010110111001101101000";
            string           B   = "1000011011000000111100110";
            AddBinaryStrings abs = new AddBinaryStrings();

            abs.addBinary(A, B);


            Anagram anagram   = new Anagram();
            bool    isAnagram = anagram.AreAnagramWithHash("anagram", "nagaram");

            Console.WriteLine(isAnagram);


            LongestPalindromicSubstring llps = new LongestPalindromicSubstring();

            llps.SingleMiddleElement("dccd");


            string        str  = "  hello world  ";
            string        str1 = "fwbpudnbrozzifml osdt ulc jsx kxorifrhubk ouhsuhf sswz qfho dqmy sn myq igjgip iwfcqq";
            ReverseString rs   = new ReverseString();

            rs.ReverseWords2(str);
            return;

            CountAndSay cands = new CountAndSay();
            var         ss    = cands.CountAndSay_Methody(6);

            Console.WriteLine(ss);
            Console.ReadKey();


            GroupAnagrams ga = new GroupAnagrams();

            ga.anagrams(new List <string>()
            {
                "cat", "dog", "god", "tca"
            });
            return;



            //Json Deserialize
            List <MyClass> myClass = new List <MyClass>();

            string json = "[{\"Name\":\"Medium Usage in Late Night Hours\",\"Status\":\"Failure\",\"ErrorCode\":[\"Policy_Not_Exist$##$Medium Usage in Late Night Hours\"]},{\"Name\":\"No Monthend Financial Postings\",\"Status\":\"Failure\",\"ErrorCode\":[\"Transaction_Not_Imported$##$No Monthend Financial Postings\"]},{\"Name\":\"High Usage\",\"Status\":\"Failure\",\"ErrorCode\":[\"Policy_Not_Exist$##$High Usage\"]}]"
            ;

            myClass = JsonConvert.DeserializeObject <List <MyClass> >(json);



            LongestPalindromicSubstring lps = new LongestPalindromicSubstring();

            Console.WriteLine(lps.LongestPSubstring());
            Console.ReadKey();
            CyclicPermutations cpermutations = new CyclicPermutations();

            cpermutations.FindCyclicPermutations();

            Tour cTour = new Tour();

            cTour.CalculateTour();

            TwitterTrend tt = new TwitterTrend();

            tt.ChkTwitterTrends();


            CommonPrime cp = new CommonPrime();

            cp.GetPrime();

            var number1 = Console.ReadLine();

            byte[] ASCIIValues = Encoding.ASCII.GetBytes(number1);
            foreach (byte b in ASCIIValues)
            {
                Console.WriteLine(b);
            }

            //var number1 = Console.ReadLine();

            //var val = (int)number1;
            //Console.WriteLine(val);



            Dictionary <string, int> list1 = new Dictionary <string, int>();

            list1.Add("b5", 4);
            list1.Add("b6", 5);
            list1.Add("a7", 4);

            var lklist1 = list1.OrderBy(x => x.Value).ThenBy(x => x.Key);

            foreach (KeyValuePair <string, int> pair in lklist1)
            {
            }



            Dictionary <string, int> list = new Dictionary <string, int>();

            list.Add("b5", 4);
            list.Add("b6", 5);
            list.Add("b5", 4);
            //list.OrderBy(x=>x.Value, new SeqComparer<KeyValuePair<string,int>>(new KeyValuePair<string,int>(x.Ke)));

            //list.Contains


            PermutationPalindrome pp1 = new PermutationPalindrome();

            pp1.CheckPalindrome();

            ZAlgorithm zAlgo     = new ZAlgorithm();
            var        solutions = zAlgo.PatternMaching("bcdfgabcd", "abcd");

            for (int i = 0; i < solutions.Count; i++)
            {
                Console.WriteLine(solutions[i]);
            }

            Console.ReadKey();

            //Thread.CurrentThread.CurrentCulture
            string number       = "123456789123";
            int    decimalIndex = number.LastIndexOf(".");

            if (decimalIndex != 0 && decimalIndex <= 13 && number.Length <= 18 ||
                decimalIndex == 0 && number.Length <= 12)
            {
                Console.WriteLine("Match1");
            }

            number       = "12345678912356577";
            decimalIndex = number.LastIndexOf(".");
            if (decimalIndex != -1 && decimalIndex <= 13 && number.Length <= 18 ||
                decimalIndex == -1 && number.Length <= 12)
            {
                Console.WriteLine("Match1");
            }

            number       = "123456789123.45678";
            decimalIndex = number.LastIndexOf(".");
            if (decimalIndex != -1 && decimalIndex <= 12 && number.Length <= 18 ||
                decimalIndex == -1 && number.Length <= 12)
            {
                Console.WriteLine("Match1");
            }

            number       = "1234567891223.45678";
            decimalIndex = number.LastIndexOf(".");
            if (decimalIndex != -1 && decimalIndex <= 12 && number.Length <= 18 ||
                decimalIndex == -1 && number.Length <= 12)
            {
                Console.WriteLine("Match1");
            }
            number       = "123456781223.456789";
            decimalIndex = number.LastIndexOf(".");
            if (decimalIndex != -1 && decimalIndex <= 12 && number.Length <= 18 ||
                decimalIndex == -1 && number.Length <= 12)
            {
                Console.WriteLine("Match1");
            }
            number       = "123456781223.4567898";
            decimalIndex = number.LastIndexOf(".");
            if (decimalIndex != -1 && decimalIndex <= 12 && number.Length <= 18 ||
                decimalIndex == -1 && number.Length <= 12)
            {
                Console.WriteLine("Match1");
            }
            int[] arr = new[] { 3, 4, 6, 7, 8, 9, 1 };

            Reverse(arr);


            RemoveAllAdjascentDuplicates rDuplicates = new RemoveAllAdjascentDuplicates();

            rDuplicates.RemoveDuplicates("abbaca");

            FindCommonCharacter commonCharacter = new FindCommonCharacter();

            commonCharacter.CommonChars(new string[] { "acabcddd", "bcbdbcbd", "baddbadb", "cbdddcac", "aacbcccd", "ccccddda", "cababaab", "addcaccd" });

            DecryptStringFromAToInt atoint = new DecryptStringFromAToInt();

            atoint.FreqAlphabets("10#11#12");

            ToLowerString lowerString   = new ToLowerString();
            string        loweredString = lowerString.ConvertTOLower("Hello");

            loweredString = lowerString.ConvertTOLower("HELLO");

            Max69Number n69obj = new Max69Number();

            n69obj.Maximum69Number(9969);


            BalancedString bs = new BalancedString();

            bs.balancedString("WQWRQQQW");

            GroupAnagrams groupAna = new GroupAnagrams();

            groupAna.groupAnagrams(new string[] { "eat", "tea", "tan", "ate", "nat", "bat" });

            RomanToInt toInt = new RomanToInt();

            toInt.ToInt("MCMIV");

            StringToAtoi toAtoi    = new StringToAtoi();
            int          converter = toAtoi.MyAtoi("   -42");

            Console.Write(converter);

            PermutationPalindrome pp = new PermutationPalindrome();

            //pp.IsPalindromicPerm("carerac");
            Console.WriteLine(pp.IsPalindromicPerm("carerac"));
            Console.WriteLine(pp.IsPalindromicPerm("aaa"));
            pp.IsPalindromicPerm("aab");
            Console.WriteLine(pp.IsPalindromicPerm("aab"));
            Console.WriteLine(pp.IsPalindromicPerm("aaa"));
            Console.WriteLine(pp.IsPalindromicPerm("abba"));
            Console.WriteLine(pp.IsPalindromicPerm("ababa"));
            Console.WriteLine(pp.IsPalindromicPerm("ababba"));
            //aab
            //carerac
            //aa
            //abba
            Console.ReadKey();


            Console.ReadKey();
        }
예제 #16
0
        public void RabinKarpTest()
        {
            RabinKarp p = new RabinKarp("TD3");

            TestTools.RunLocalTest("A10", p.Process, p.TestDataName);
        }
예제 #17
0
        static void Main(string[] args)
        {
            // StringProblems
            //Test calls for Reverse string
            string input = "jacob";

            Console.WriteLine(input + "<=>" + new string(SimpleProblem.ReverseString(input.ToCharArray())));
            input = "jake";
            Console.WriteLine(input + "<=>" + new string(SimpleProblem.ReverseString(input.ToCharArray())));
            input = "";
            Console.WriteLine(input + "<=>" + new string(SimpleProblem.ReverseString(input.ToCharArray())));
            input = "jdshjdh@#$%^&)";
            Console.WriteLine(input + "<=>" + new string(SimpleProblem.ReverseString(input.ToCharArray())));

            ReplaceSpaces.TestReplaceSpacesInplace();
            Anagrams.TestIsAnagramAlgo();
            StringRotation.TestIsThisRotatedString();
            RemoveDuplicates.TestRemoveDuplicatesFromString();
            StringToLongConverter.TestStringToLong();
            RegexMatching.TestMatch();
            SumOfTwoNumbersInArray.TestSumOfTwoNumbersInArray();
            SumOfThreeNumbersInArray.TestSumOfThreeNumbersInArray();
            PairInSortedArrayClosestToAParticularValue.TestPairInSortedArrayClosestToAParticularValue();
            PalindromeInStringPermutation.TestPalindromeInStringPermutation();
            EditDistanceBetweenStrings.TestEditDistanceBetweenStrings();
            AnagramIsPalindrome.TestAnagramIsPalindrome();
            GreatestPalindrome.TestGreatestPalindrome();
            ReverseStringWithoutVowels.TestReverseStringWithoutVowels();
            LongestSubstringWithKDistinctChars.TestLongestSubstringWithKDistinctChars();
            // Pattern Matching
            NativePatternMatching.TestNativePatternMatching();
            KMPPatternMatching.TestKMPPatternMatching();
            BoyerMoorePatternMatching.TestPatternMatching();
            RabinKarp.TestRabinKarp();

            //Console.ReadLine();

            //Array Problems
            ArrayOfNumsIncrement.TestIncrementArrayOfNumbers();
            MajorityElement.TestFindMajorityElement();
            Merge2SortedArrays.TestMergeSortedArrays();
            MaxDistanceInArray.TestMaxDistanceInArray();
            MovingAverage.TestMovingAverage();
            TotalAverage.TestTotalAverage();
            ArrayWithGreaterElementToRight.TestArrayWithGreaterElementToRight();
            WaterCollectedInPuddleShownByHistogram.TestWaterCollectedInPuddleShownByHistogram();
            CountOfPairsWhichSumUpToGivenSum.TestCountOfPairsWhichSumUpToGivenSum();
            //Median.TestGetMedianOf2SortedArray();

            // Sorting Problems
            SelectionSort.TestSorting();
            BubbleSort.TestSorting();
            InsertionSort.TestSorting();
            ShellSort.TestSorting();
            MergeSort.TestMergeSort();
            QuickSort.TestQuickSort();
            HeapSortTester.TestHeapSort();
            CountingSort.TestSorting();
            RadixSort.TestRadixSort();
            DutchNationalFlag.TestDutchNationalFlag();
            SortedSquares.TestSortedSquares();

            // Matrix Problem
            Rotate_Matrix_90_degree.TestRotateMatrix();
            Matrix_Column_Rows_0.TestMakeRowColZero1();
            Matrix_Column_Rows_0.TestMakeRowColZero2();
            RotateMatrix180.TestRotateMatrix180();
            SumOfMatrixElementsFormedByRectangleWithCoordinates.TestSumOfMatrixElements();
            SortedArrayFromSortedMatrix.TestSortedArrayFromSortedMatrix();
            SearchWordInMatrix.TestSearchWordInMatrix();
            MaxOnesInRow.TestMaxOnesInRow();
            MatrixAsTriangle.TestMatrixAsTriangle();
            MinRangeInMatrix.TestMinRangeInMatrix();
            PrintMatrixAsSnake.TestPrintMatrixAsSnake();
            PrintMatrixInSpiral.TestPrintMatrixInSpiral();
            MaxSqAreaInBinaryMatrix.TestMaxRectAreaInBinaryMatrix();
            TicTacToeWinner.TestTicTacToeWinner();
            WaterfallCreation.TestWaterfallCreation();

            // Linked list Problems
            DeleteLinkedListNode.TestDeleteFirstNode();
            DeleteDuplicatesFromLinkedList.TestDeleteDuplicates();
            NthLastElementOfLinkedList.TestNthLastNodeOfLinkedList();
            DeleteNodeWithDirectReference.TestDeleteNode();
            AddNumbers.TestAddNumbersRepresentedByLinkedList();
            CopyLinkedListWithRandomNode.TestGetCopiedLinkedListWithRandomNode();
            CommonElementInTwoLinkedList.TestCommonElement();
            ReverseAdjacentNodesInLinkedList.TestReverseAdjacentNodes();
            MergeSortedLinkedList.TestMerge();
            CycleInLinkedList.TestStartOfCycleInLinkedList();
            MedianForCircularLinkedList.TestGetMedian();
            ReverseLinkedList.TestReverseLinkedList();
            SortedCircularLinkedList.TestCircularLinkedList();

            // stack and queue problem
            ThreeStackWithOneArray.TestThreeStackWithOneArray();
            StackWithMinElement.TestStackWithMinElement();
            StackOfPlates.TestStackOfPlates();
            SortAStack.TestSortAStackAscending();
            WellFormedExpression.TestWellFormedExpression();
            QueueVia2Stack.TestQueueVia2Stack();
            LRUCache.TestLRUCache();
            EvaluatePrefixNotation.TestGetPrefixNotationResult();
            EvaluateInflixNotation.TestGetInflixNotationResults();
            EvaluatePostfixNotation.TestGetPostfixNotationResult();
            TestCircularQueue.TestCircularQueueWithDifferentCases();
            LargestAreaInHistogram.TestLargestAreaInHistogram();
            TextEditerWithUndo.TestTextEditerWithUndo();

            //Recursion Problem
            TowerOfHanoi.TestTowerOfHanoi();
            MaxSumOfConsecutiveNums.TestMaxSumOfConsecutiveNums();

            // Back tracking problems
            Sudoku.TestSudokuSolver();
            HamiltonianCycle.TestHamiltonianCycle();
            GraphColoringWithMColors.TestGraphColoringWithMColors();
            MakeLargestIsland.TestMakeLargestIsland();

            //Misc Problem
            MinNumOfCoins.TestMinNumOfCoins();
            IsPrime.TestCheckPrime();
            SquareRoot.TestCalculateSquareRoot();
            CreditCardCheck.TestLuhnAlgo();
            ExcelFirstRowConversion.TestCovertExcelColumnToLong();
            Skyline.TestSkyline();
            SumOfSquaresWithoutMultiplication.TestSumOfSquares();
            MergeIntervals.TestMergeIntervals();
            WidthOfCalendar.TestWidthOfCalendar();
            JosephusProblem.TestJosephusProblem();

            // Permutation and Combination problem
            ShuffleAList.TestFisherYatesAlgo();
            CombinationsOfBinaryString.TestCombinationsOfBinaryString();
            AllCombinationsOfString.TestAllCombinationsOfString();
            AllPermutationsOfString.TestAllPermutationsOfString();
            PhoneNumberToWords.TestPhoneNumberToWords();
            AllNumbersInRangeWithDifferentDigits.TestAllNumbersInRangeWithDifferentDigits();
            DivideSetIntoTwoEqualSetsWithMinSumDiff.TestDivideSetIntoTwoEqualSetsWithMinSumDiff();
            PowerSet.TestPowerSet();
            AllCombinationsOfParenthesis.TestAllCombinationsOfParenthesis();
            GoodDiceRoll.TestGoodDiceRoll();
            PermutationsOfValidTime.TestPermutationsOfValidTime();

            // Tree Problems
            TreeFromExpression.TestCreateTreeFromExpression();
            TestBinarySearchTree.TestDifferentOperationsOnBST();
            AncestorOfTwoNodesInBST.TestAncestorOfTwoNodesInBST();
            CheckBTisBST.TestCheckBTisBST();
            MaxSumOnTreeBranch.TestMaxSum();
            WalkTheTree.TestWalkTheTree();
            SkewedBSTToCompleteBST.TestConvertSkewedBSTToCompleteBST();
            CheckIfTheTreeIsBalanced.TestIsTreeBalanced();
            LinkedListOfTreeNodesAtEachDepth.TestCreateLinkedListOfTreeNodesAtEachDepth();
            PrintBinaryTreeNodeAtEachLevel.TestPrintBinaryTreeNodeAtEachLevel();
            PrintBinaryTreeNodeAtEachLevelSpirally.TestPrintBinaryTreeNodeAtEachLevelSpirally();
            TreeSubtreeOfAnother.TestMatchTree();
            AncestorOfTwoNodesInBT.TestGetAncestorOfTwoNodesInBT();
            AncestorOfMultiNodesInBT.TestAncestorOfMultiNodesInBT();
            LinkedListFromLeavesOfBT.TestLinkedListFromLeavesOfBT();
            ExteriorOfBT.TestPrintExteriorOfBT();
            DepthOfTree.TestGetDepthOfTree();
            TreeToColumns.TestTreeToColumns();
            KthSmallestElementFromBST.TestKthSmallestElementFromBST();
            MakeBSTFromPreOrder.TestMakeBSTFromPreOrder();
            MirrorATree.TestMirrorATree();
            CloneABTWithRandPointer.TestCloneABTWithRandPointer();
            TreeWithInorderAndPreorder.TestTreeWithInorderAndPreorder();
            TreeWithInorderAndPostorder.TestTreeWithInorderAndPostorder();
            TreePathSumsToValue.TestTreePathSumsToValue();
            AllPathInNArayTree.TestAllPathInNArayTree();
            SerializeDeserializeBinaryTree.TestSerializeDeserializeBinaryTree();
            SerializeDeserializeAnNaryTree.TestSerializeDeserializeAnNaryTree();
            AncestorOfTwoNodesInNaryTree.TestAncestorOfTwoNodesInNaryTree();
            AbsOfMaxAndSecondMaxDepthInBT.TestGetAbsOfMaxAndSecondMaxDepthInBT();

            // Trie problems
            CreateAndSearchSimpleTrie.TestCreateAndSearchSimpleTrie();
            // ToDo: have a problem of suffix trees
            ShortestPrefix.TestGetShortestPrefixNotPresentInStringSet();

            // Dynamic Programming problems
            LongestCommonSubsequence.TestGetLongestCommonSubsequence();
            LongestPalindromeSubString.TestGetLongestPalindromeSubString();
            LongestPalindromicSubsequence.TestGetLongestPalindromicSubsequence();
            MaximumAs.TestGetMaximumAs();
            MinNumberOfJumps.TestGetMinimumNumberOfJumps();
            LongestCommonSubString.TestGetLongestCommonSubString();
            KnapSackProblem.TestGetTheMaximumValueWithLimitedWeight();
            TreeCuttingProblem.TestGetTreeCuttingToMaximizeProfits();
            WordBreaking.TestBreakTheWords();
            DistanceOfWords.TestDistanceOfWords();
            LongestIncreasingSubSequence.TestLongestIncreasingSubSequence();
            MinCostPath.TestMinCostPath();
            DifferentWaysForCoinChange.TestDifferentWaysForCoinChange();
            MatrixMultiplication.TestMatrixMultiplication();
            BinomialCoefficient.TestBinomialCoefficient();
            BoxStacking.TestBoxStacking();
            WordWrapping.TestWordWrapping();
            MaxSubMatrixWithAllOnes.TestMaxSubMatrixWithAllOnes();
            LongestSubStringWithEqualSum.TestLongestSubStringWithEqualSum();
            PartitionArrayIntoEqualSumSets.TestPartitionArrayIntoEqualSumSets();
            MaxSumRectangle.TestMaxSumRectangle();
            RegularExpressionMatch.TestRegularExpressionMatch();
            NumRepresentedByPerfectSquares.TestNumRepresentedByPerfectSquares();
            LongestCommonSubsequenceInSameString.TestLongestCommonSubsequenceInSameString();
            StringDecodeAsAlphabets.TestStringDecodeAsAlphabets();
            BalloonBursting.TestBalloonBursting();
            TravellingSalesmanProblem.TestTravellingSalesmanProblem();
            MaxSumWithoutAdjacentElements.TestMaxSumWithoutAdjacentElements();
            MaxPathThroughMatrix.TestMaxPathThroughMatrix();
            BrickLaying.TestBrickLaying();
            JobSchedullingWithConstraints.TestJobSchedullingWithConstraints();
            EggDropMinTrials.TestEggDropMinTrials();

            // Graph Problems
            ShortestPath.TestGetShortestPathBetween2Vertex();
            CycleInDirectedGraph.TestIsCycleInDirectedGraph();
            CycleInUnDirectedGraph.TestIsCycleInUnDirectedGraph();
            SolveAMaze.TestSolveAMaze();
            AllPathsGivenStartEndVertex.TestGetAllPathsInGraphFromStartVertexToEndVertex();
            AllPaths.TestGetAllPathsInGraphFromStartVertex();
            ColorVertices.TestColorVerticesWithDifferentColor();
            CheckBipartiteGraph.TestCheckBipartiteGraph();
            TransformOneWordToAnother.TestGetTransformation();
            ConstraintsVerification.TestConstraintsVerification();
            ExtendedContactsInSocialNetwork.TestComputeExtendedContacts();
            CourseScheduling.TestCourseScheduling();
            SnakeAndLadder.TestSnakeAndLadder();
            IsGraphATree.TestIsGraphATree();
            ReverseGraph.TestReverseGraph();
            StronglyConnectedGraph.TestStronglyConnectedGraph();
            ConnectedComponents.TestConnectedComponents();
            ContinentalDivide.TestContinentalDivide();
            CloneGraph.TestCloneGraph();
            Wordament.TestWordament();
            // ShortestPathAlgo
            FloydWarshall.TestFloydWarshall();
            DijkstraAlgorithm.TestDijkstraAlgorithm();
            BellmanFord.TestBellmanFord();
            TravelFromLeftToRightInMatrix.TestTravelFromLeftToRightInMatrix();
            HeuristicSearch.TestHeuristicSearch();
            AStar.TestAStar();
            ShortestPathWhenObstaclesRemoved.TestShortestPathWhenObstaclesRemoved();
            ShortestDistanceFromRoomsToGates.TestShortestDistanceFromRoomsToGates();
            //MaxFlow
            FordFulkersonEdmondKarp.TestFordFulkersonEdmondKarp();
            MinCut.TestMinCut();
            MaximumBipartiteMatching.TestMaximumBipartiteMatching();
            //Minimum Spanning Tree
            KruskalAlgorithm.TestKruskalAlgorithm();
            PrimsAlgorithm.TestPrimsAlgorithm();


            //Heap problems
            BasicMaxHeap.TestMaxHeap();
            BasicMinHeap.TestMinHeap();
            TestMinHeapMap.DoTest();
            TestPriorityQueue.Run();
            MedianForAStreamOfNumbers.TestMedianForAStreamOfNumbers();

            //DisjointSets
            TestingDisjointSet.Run();
            //TestWeightedDisjointSetsWithPathCompression.Run(); // this runs slow, hence commenting it

            //Geometry
            ClosestPairOfPoints.TestClosestPairOfPoints();
            RectangleIntersection.TestRectangleIntersection();
            LineSegmentIntersection.TestLineSegmentIntersection();
            ConvexHull.TestConvexHull();
            KClosestPointToOrigin.TestKClosestPointToOrigin();

            //Greedy Algorithm
            HuffmanCoding.TestHuffmanCoding();

            //Randomized Algorithm
            RandomGeneration.TestRandomGeneration();

            // Bit Algorithms
            IntHaveOppositeSigns.TestIntHaveOppositeSigns();
            Parity.TestParity();

            //Math Problem
            ZerosInFactorial.TestZerosInFactorial();
            GetAllPrimeFactors.TestGetAllPrimeFactors();
            NumberOfFactors.TestNumberOfFactors();
            AllFactors.TestAllFactors();
            MultiplyLongNumbers.TestMultiplyLongNumbers();
            NextLargestPermutation.TestNextLargestPermutation();
            AllPrimesTillN.TestAllPrimesTillN();
            PascalsTriangle.TestPascalsTriangle();
            SubtractLongNumbers.TestSubtractLongNumbers();

            //Search problems
            SearchInSortedRotatedArray.TestSearchInSortedRotatedArray();
            KClosestElementInArray.TestKClosestElementInArray();
            SearchInSortedMatrix.TestSearchInSortedMatrix();
            BinarySearchUnbounded.TestBinarySearchUnbounded();
            LinkedListSublistSearch.TestLinkedListSublistSearch();
            NoOfOccuranceInSortedArray.TestNoOfOccuranceInSortedArray();
            GetSmallestInSortedRotatedArray.TestGetSmallestInSortedRotatedArray();

            //Distributed algorithms
            KWayMerge.TestKWayMerge();


            Console.ReadLine();
        }
예제 #18
0
        public void RabinKarp_Test()
        {
            ISearch kmpSearch = new RabinKarp();

            AssertStringSearch(kmpSearch);
        }
예제 #19
0
 public int[] FindAllOccurrences_IDM_Test(string text, string pattern)
 {
     return(RabinKarp.FindAllOccurrences(text, pattern).ToArray());
 }
예제 #20
0
 public RabinKarpTests()
 {
     _rabinKarp = new RabinKarp();
 }