Exemplo n.º 1
0
        static void quickSortBootLoader()
        {
            DivideAndConquer divideAndConquer = new DivideAndConquer();

            List <long> ma = null;
            List <long> ca = new List <long>();
            string      m1 = null; string m2 = null;

            while (true)
            {
                var watch = new Stopwatch();

                int[] arr  = divideAndConquer.GetRandomArray(65536); /*new int[] { 1, 6, 1, 3, 9, 7 };*/
                int[] arr2 = new int[arr.Length]; arr.CopyTo(arr2, 0);

                watch.Start();
                divideAndConquer.QuickSort(arr);
                watch.Stop();

                if (ma is null)
                {
                    ma = new List <long>();
                }
                else
                {
                    ma.Add(watch.ElapsedTicks);
                    m1  = string.Format("Current Implementation Time : {0}, average time {1}", watch.ElapsedTicks, ma.Average());
                    m1 += "\n" + divideAndConquer.CheckArraySorted(arr);
                }

                watch = new Stopwatch();
                watch.Start();
                Array.Sort(arr2);
                watch.Stop();

                ca.Add(watch.ElapsedTicks);
                m2 = string.Format("C# Time : {0}, average time {1}", watch.ElapsedTicks, ca.Average());

                //Console.ReadLine();
                System.Threading.Thread.Sleep(100);
                Console.Clear();
                Console.WriteLine(m1);
                Console.WriteLine(m2);
            }
        }
 public void GrahamScanNormalTestCase3000Points()
 {
     convexHullTester = new DivideAndConquer();
     Case3000Points();
 }
 public void DivideAndConquerSpecialCaseTriangle()
 {
     convexHullTester = new DivideAndConquer();
     SpecialCaseTriangle();
 }
 public void DivideAndConquerSpecialCaseConvexPolygon()
 {
     convexHullTester = new DivideAndConquer();
     SpecialCaseConvexPolygon();
 }
 public void DivideAndConquerTestCase10()
 {
     convexHullTester = new DivideAndConquer();
     Case10();
 }
 public void DivideAndConquerNormalTestCase10000Points()
 {
     convexHullTester = new DivideAndConquer();
     Case10000Points();
 }
Exemplo n.º 7
0
 public void Test_DiffWaysToCompute()
 {
     Assert.AreEqual(2, DivideAndConquer.DiffWaysToCompute("2-1-1").Count);
     Assert.AreEqual(5, DivideAndConquer.DiffWaysToCompute("2*3-4*5").Count);
 }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
start:
            Console.WriteLine("Data structures and Algorithm \n");

            Console.WriteLine("" +
                              "Please enter the Algorithm paradigm number. \n" +
                              "*******************************************\n" +
                              "1. Divide and Conqure \n" +
                              "2. Greedy Algorithms \n" +
                              "3. Dynamic Programming \n" +
                              "4. Search And Sort Algorithms \n" +
                              "5. Other Algorithms \n" +
                              "6. Exit \n" +
                              "******************************************* \n\n" +
                              "Please enter your choice\n"

                              );

            int algoSec = Convert.ToInt16(Console.ReadLine());
            int algoNum;

            switch (algoSec)
            {
            case 1:
                Console.WriteLine(
                    "Divide And Conqure \n \n" +
                    "******************\n" +
                    "1. Binary Search \n" +
                    "2. Merge Sort \n" +
                    "3. Quick Sort \n" +
                    "4. Closest Pair of Points \n" +
                    "5. Strassen's Matrix Multiplication \n" +
                    "6. Karatsuba Multiplication \n" +
                    "7. Cooley-Tukey Fast Fourier Transformation \n" +
                    "8. Multiply 2 Polynomials \n" +
                    "******************" +
                    "\n Please enter the Algorithm Number. \n"
                    );

                algoNum = Convert.ToInt16(Console.ReadLine());

                switch (algoNum)
                {
                case 1:
                    DivideAndConquer.BinarySearch();
                    goto start;

                case 2:
                    DivideAndConquer.MergeSort();
                    goto start;

                case 3:
                    DivideAndConquer.QuickSortMain();
                    goto start;

                case 4:
                    DivideAndConquer.ClosestPairOfPoint();
                    goto start;

                case 5:
                    DivideAndConquer.MatrixMultiplication();
                    goto start;

                case 6:
                    DivideAndConquer.KaratsubaMultiplication();
                    goto start;

                case 7:
                    DivideAndConquer.CooleyTukeyFTT();
                    goto start;

                case 8:
                    DivideAndConquer.MultiplyTwoPolynomial();
                    goto start;
                }

                break;

            case 2:
                Console.WriteLine(
                    "Greedy Algorithm \n \n" +
                    "*****************\n" +
                    "1. \n" +
                    "******************" +
                    "\n Please enter the Algorithm Number. \n"
                    );
                algoNum = Convert.ToInt16(Console.ReadLine());

                switch (algoNum)
                {
                case 1:
                    goto start;
                }

                break;

            case 3:
                Console.WriteLine(
                    "Dynamic Programming\n \n" +
                    "*****************\n" +
                    "1. \n" +
                    "******************" +
                    "\n Please enter the Algorithm Number. \n"
                    );
                algoNum = Convert.ToInt16(Console.ReadLine());

                switch (algoNum)
                {
                case 1:
                    goto start;
                }

                break;

            case 4:
                Console.WriteLine(
                    "Search and Sorting Algorithm \n \n" +
                    "*****************************\n" +
                    "1. Linear Search \n" +
                    "2. Selection Sort \n" +
                    "3. Insertion Sort \n" +
                    "******************" +
                    "\n Please enter the Algorithm Number. \n"
                    );
                algoNum = Convert.ToInt16(Console.ReadLine());

                switch (algoNum)
                {
                case 1:
                    SearchAndSort.LinearSearch();
                    goto start;

                case 2:
                    SearchAndSort.SelectionSortAlgo();
                    goto start;

                case 3:
                    SearchAndSort.InsertionSort();
                    goto start;
                }
                break;

            case 5:
                Console.WriteLine(
                    "Other Algorithms \n \n" +
                    "****************\n" +
                    "1.  \n" +
                    "******************" +
                    "\n Please enter the Algorithm Number. \n"
                    );
                algoNum = Convert.ToInt16(Console.ReadLine());

                switch (algoNum)
                {
                case 1:
                    goto start;
                }
                break;

            case 6:
                Environment.Exit(0);
                break;
            }
        }
Exemplo n.º 9
0
 public void DivideAndConquerSpecialCase10SamePoints()
 {
     convexHullTester = new DivideAndConquer();
     SpecialCase10SamePoints();
 }
Exemplo n.º 10
0
 public void ZTraversal(int expected, int dimensions, int x, int y)
 {
     Assert.Equal(expected, DivideAndConquer.ZTraversal(dimensions, x, y));
 }
Exemplo n.º 11
0
 public void MaximumSumSubArray(int expectedResult, int[] array)
 {
     Assert.Equal(expectedResult, DivideAndConquer.MaximumSumSubArray(array));
 }