private void button2_Click(object sender, EventArgs e)
        {
            int size = Convert.ToInt32(this.textBox16.Text);

            int[] input = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox11.Text);
            this.textBox13.Text = FindtheMissingNumberUsingXOR(input, size).ToString();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            int[] array1 = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox5.Text);
            int[] array2 = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox6.Text);

            this.textBox8.Text = FindMedianofSortedArrayUnEqualSizeWrapper(array1, array2).ToString();
        }
        private void button4_Click(object sender, EventArgs e)
        {
            int[] input1 = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox2.Text);
            int[] input2 = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox3.Text);

            this.textBox1.Text = FindMissingNumberUsingHashtable(input1, input2).ToString();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            //Input: 1,2,4,7,10,11,7,12,6,7,16,18,19
            //Given an sequence of integers. Find the unsorted sequence of the given list
            //1)Find the longest increasing susbsequence at the beginning and the longest increasing subsequence at the end..
            //   Thus divide the input into three left: 1,2,4,7,10,11  - Middle 7,12   Right 6,7,16,18,19
            //2) In order to solve the problem we got to maintain left  < middle < right and the answer is the start and end of the middle
            //   but here the middle is unsorted so the right condition is =
            //  end of left < min(middle) and max(middle) < start of right
            //Important: we need to  find the min and max index by consideraing the end_left and start_right else it will not be right
            //3) To maintain the condition shrink the left and right and extend the middle untill the condition is satisfied
            //   eg:  left: 1,2,4  Middle  7, 10, 11, 7, 12,6, 7  Right: 16, 18,19
            //Answer is 7,10,11,7,12,6, 7 where m = 3 and n = 9

            int[]      input  = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox6.Text);
            SortResult result = FindUnSortedSequence(input);

            this.textBox7.Text = result.M.ToString();
            this.textBox8.Text = result.N.ToString();

            StringBuilder sb = new StringBuilder();

            for (int i = result.M; i <= result.N; i++)
            {
                sb.Append(input[i].ToString()).Append(",");
            }
            this.textBox4.Text = sb.ToString();

            //Test Cases

            //Input: 1,2,4,7,10,11,7,17,3,7,16,18,19
        }
Exemplo n.º 5
0
        private void button4_Click_1(object sender, EventArgs e)
        {
            //http://www.careercup.com/question?id=5772881111810048

            //http://stackoverflow.com/questions/5534063/zero-sum-subarray

            /* ex: 2 3 -4 9 -1 -7 -5 6 5
             * sum to enter in hash table : 0 2 5 1 10 9 2 -3 3 8
             * index to enter in hash table: -1 0 1 2 3 4 5 6 7 8
             * Logic:
             * 1) Create an ht with sum as key and list of index as value
             * 2)  we add the base value in the ht as sum 0 and index -1 because if we encounter 0 in the iteration then we found the subarray of value 0
             * 3) We iterate the given array from 0 to array.length -1
             * 4) In the iteration we make the sum of the previous elements with the current element and use the sum as the key to ht
             * 5) If the ht does not contain the sum. add sum as the key and value as the index (index list)
             * 6) If the ht contains the sum, then we found the subarray having the value of zero
             * grab the index of the sum in the ht with ht[sum]. The index sum and the current item sum is equla to 0 so that mean the items from index + 1 to current index sum will be zero
             * print the values from index + 1 to current index
             * The reason we have List<int> as value is we might have multiple sum value so each key might have multiple indexes like below
             * int[] array = {0, 1, -1, 0}  we need to print every subarray the can cause the sum to 0  eg (0) (1,-1) (0,1,-1) etc
             *
             *
             */

            int[] input = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox6.Text);

            List <string> result = FindSubArraySumOfzero(input);

            this.textBox5.Text = AlgorithmHelper.ConvertStringListArrayToSpaceSeparatedString(result);
        }
Exemplo n.º 6
0
        private void button9_Click(object sender, EventArgs e)
        {
            int[] input = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox12.Text);

            //calculate sum and avg

            int sum = 0;

            foreach (int i in input)
            {
                sum += i;
            }

            double avg = sum / input.Length;

            //sort the given array
            Array.Sort(input);
            //get the first index
            int index = FindTheFirstLargestOfGiven(input, avg);

            StringBuilder sb = new StringBuilder();

            for (int i = index; i < input.Length; i++)
            {
                sb.Append(input[i]).Append(",");
            }


            this.textBox10.Text = sb.ToString();
            this.textBox11.Text = avg.ToString();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            int[] input = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox4.Text);

            // arrange

            // Heap<int> minheap = new Heap<int>(new List<int>(), 0, new KarthicMinHeapComparer());

            MinHeap <int> minheap = new MinHeap <int>(new KarthicMinHeapComparer2());


            foreach (int i in input)
            {
                minheap.Insert(i);
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < input.Length; i++)
            {
                sb.Append(minheap.PopRoot().ToString()).Append(",");
            }

            this.textBox3.Text = sb.ToString();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            int[] array = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox1.Text);

            KarthicBST <int> tree = new KarthicBST <int>();

            tree.Root = ConstructTreeusingStacks(array);

            string output = tree.PreOrderTraversal(tree.Root);

            bool result = String.Equals(this.textBox1.Text, output.Substring(0, output.LastIndexOf(',')), StringComparison.OrdinalIgnoreCase);

            //test

            KarthicBST <int> tree1 = TreeHelper.SetUpBinarySearchTree();

            string test1 = tree1.PreOrderTraversal(tree1.Root);

            int[] input2 = AlgorithmHelper.ConvertCommaSeparetedStringToInt(test1);


            KarthicBST <int> tree3 = new KarthicBST <int>();

            tree3.Root = ConstructTreeusingStacks(input2);

            string test2 = tree3.PreOrderTraversal(tree3.Root);

            bool result2 = String.Equals(test1, test2, StringComparison.OrdinalIgnoreCase);
        }
Exemplo n.º 9
0
        private void button5_Click(object sender, EventArgs e)
        {
            int[] input = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox7.Text);

            //Logic
            //sort the given array
            //if the input size is odd, return the middle element
            // if the input size is even, calculate the mean of middle and middle + 1 element
            double median;

            Array.Sort(input);

            if (input.Length % 2 == 0)
            {
                //even
                int middle = input.Length / 2;
                median = (input[middle - 1] + input[middle]) / 2;
            }
            else
            {
                int middle = input.Length / 2;

                median = input[middle];
            }


            this.textBox8.Text = median.ToString();
        }
        private void button12_Click(object sender, EventArgs e)
        {
            int[] input = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox20.Text);

            //this.textBox8.Text = maxvalue.ToString(); we need to do extra logic to do value and its easy..no time now

            this.textBox22.Text = FindSingleMissingNumberInConsecutiveNumbersint(input).ToString();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int[] input        = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox15.Text);
            int   firstnumber  = Convert.ToInt32(this.textBox15.Text);
            int   secondnumber = Convert.ToInt32(this.textBox1.Text);

            this.textBox12.Text = ReverseFibonacciSeriesByIteration(firstnumber, secondnumber);
        }
        private void button6_Click(object sender, EventArgs e)
        {
            int[]       input  = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox11.Text);
            SequenceSum result = FindMaxSumAndSequenceWithAllNegativeHandle(input);

            this.textBox10.Text = result.MaxSum.ToString();
            this.textBox12.Text = result.Sequence;
        }
Exemplo n.º 13
0
        private void button1_Click(object sender, EventArgs e)
        {
            string[] input = AlgorithmHelper.ConvertCommaSeparetedStringToStringArray(this.textBox3.Text);

            string output = FindLongestWordMadeofotherwords(input);

            this.textBox1.Text = output;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            int[]  input  = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox4.Text);
            int    m      = Convert.ToInt32(this.textBox5.Text);
            string output = AlgorithmHelper.ConvertIntArrayToCommaSeparatedString(GeneratorRandomArrayMethod1(input, m));

            this.textBox2.Text = output;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int[] input = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox3.Text);

            string output = AlgorithmHelper.ConvertIntArrayToCommaSeparatedString(ShuffleArray(input));

            this.textBox1.Text = output;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            int[]  input      = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox16.Text);
            int    windowsize = Convert.ToInt32(this.textBox1.Text);
            string output     = AlgorithmHelper.ConvertIntArrayToCommaSeparatedString(MaxOfSlidingWindow(input, windowsize));

            this.textBox11.Text = output;
        }
Exemplo n.º 17
0
        private void button7_Click(object sender, EventArgs e)
        {
            int value = Convert.ToInt32(this.textBox8.Text);

            int[] denom = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox9.Text);
            //pass the highest denom available
            this.textBox7.Text = CountWaysDP(denom, value).ToString();
        }
        private void button12_Click(object sender, EventArgs e)
        {
            int[] array1   = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox10.Text);
            int[] array2   = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox9.Text);
            int   k        = Convert.ToInt32(this.textBox11.Text);
            int   smallest = FindKthSmallestNaiveApproachWrapper(array1, array2, k);

            this.textBox7.Text = smallest.ToString();
        }
        private void button13_Click(object sender, EventArgs e)
        {
            int[] array1   = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox10.Text);
            int[] array2   = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox9.Text);
            int   k        = Convert.ToInt32(this.textBox11.Text);
            int   smallest = FindKthSmallestUsingInvariant(array1, 0, array1.Length - 1, array2, 0, array2.Length - 1, k);

            this.textBox7.Text = smallest.ToString();
        }
        private void button4_Click(object sender, EventArgs e)
        {
            int[] input = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox11.Text);

            MedianOfMedian med    = new MedianOfMedian(input);
            int            median = med.FindMiddleElement(input, 0, input.Length - 1);

            this.textBox15.Text = median.ToString();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            int[] array = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox2.Text);
            int   sum   = Convert.ToInt32(this.textBox4.Text);

            string output = FindPairsBySort(sum, array);

            this.textBox5.Text = output;
        }
        private void button8_Click(object sender, EventArgs e)
        {
            int[]            input = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox5.Text);
            int              index = Convert.ToInt32(this.textBox8.Text);
            int              value = Convert.ToInt32(this.textBox9.Text);
            SegmentationTree tree  = new SegmentationTree(input);

            tree.UpdateValueAtindex(index, value);
            this.textBox5.Text = AlgorithmHelper.ConvertIntArrayToCommaSeparatedString(tree.InputArray);
        }
        private void button12_Click(object sender, EventArgs e)
        {
            int[] input = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox13.Text);
            int   i     = Convert.ToInt32(this.textBox15.Text);
            //this sln is for ith..for length
            //i = i - 1;
            string output = SortHelper.FindtheLargest(input, i).ToString();

            this.textBox14.Text = output;
        }
Exemplo n.º 24
0
        private void button4_Click(object sender, EventArgs e)
        {
            int[]  input      = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox3.Text);
            int    m          = Convert.ToInt32(this.textBox2.Text);
            string output     = "";
            bool   ispossible = isSubsetSum(input, input.Length, m);

            this.textBox4.Text = ispossible == true ? "Yes" : "No";
            this.textBox1.Text = output;
        }
Exemplo n.º 25
0
        private void button1_Click(object sender, EventArgs e)
        {
            //https://www.youtube.com/watch?v=cETfFsSTGJI

            int[] input = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox15.Text);

            JumpItem result = MinimumNumberofJumpsDP(input);

            this.textBox12.Text = result.MinimumJump.ToString();
            this.textBox1.Text  = result.Path;
        }
        private void button4_Click(object sender, EventArgs e)
        {
            int[] weights  = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox6.Text);
            int[] values   = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox1.Text);
            int   capacity = Convert.ToInt32(this.textBox2.Text);

            var result = FindKnackSnapMaxValueWithItems(capacity, weights, values, 0);

            this.textBox3.Text = result.Max.ToString();
            this.textBox4.Text = result.Items;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            //https://www.youtube.com/watch?v=_H50Ir-Tves
            //http://www.geeksforgeeks.org/median-of-two-sorted-arrays-of-different-sizes/


            int[] array1 = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox5.Text);
            int[] array2 = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox6.Text);

            this.textBox8.Text = FindingMedianofSortedArray(array1, array2).ToString();
        }
        private void button13_Click(object sender, EventArgs e)
        {
            char[] input1 = AlgorithmHelper.ConvertCommaSeparetedStringToCharArray(this.textBox1.Text);

            this.textBox4.Text = FindSubSequenceOfLengthTwo(input1).ToString();

            this.textBox5.Text = FindSubSequenceOfLengthTwo(AlgorithmHelper.ConvertCommaSeparetedStringToCharArray(this.textBox2.Text)).ToString();


            this.textBox6.Text = FindSubSequenceOfLengthTwo(AlgorithmHelper.ConvertCommaSeparetedStringToCharArray(this.textBox3.Text)).ToString();
        }
Exemplo n.º 29
0
        private void button3_Click(object sender, EventArgs e)
        {
            int[] array = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox1.Text);

            KarthicBST <int> tree = new KarthicBST <int>();

            tree.Root = ConstructTreeWithMinAndMax(array, 0, Int32.MinValue, Int32.MaxValue, array[0]).treenode;

            string output = tree.PreOrderTraversal(tree.Root);

            bool result = String.Equals(this.textBox1.Text, output.Substring(0, output.LastIndexOf(',')), StringComparison.OrdinalIgnoreCase);
        }
Exemplo n.º 30
0
        private void button1_Click(object sender, EventArgs e)
        {
            int[] array = AlgorithmHelper.ConvertCommaSeparetedStringToInt(this.textBox1.Text);

            KarthicBST <int> tree = new KarthicBST <int>();

            tree.Root = BuildTreeWithPreOrderArray(array, 0, 0, array.Length - 1).treenode;

            string output = tree.PreOrderTraversal(tree.Root);

            bool result = String.Equals(this.textBox1.Text, output.Substring(0, output.LastIndexOf(',')), StringComparison.OrdinalIgnoreCase);
        }