public static void TestMaxRectAreaInBinaryMatrix()
        {
            MaxSqAreaInBinaryMatrix mr = new MaxSqAreaInBinaryMatrix();

            int[,] mat = new int[, ]
            {
                { 0, 1, 1, 1 },
                { 1, 1, 0, 1 },
                { 0, 0, 0, 1 },
                { 0, 1, 1, 1 },
                { 1, 1, 1, 1 },
                { 0, 1, 1, 1 },
                { 0, 1, 1, 1 },
            };

            Console.WriteLine("The input matrix is as shown below:");
            MatrixProblemHelper.PrintMatrix(mat);
            Console.WriteLine("The max square is at {0}", mr.GetMaxRectArea(mat));

            mat = new int[, ]
            {
                { 1, 0, 1 },
                { 0, 1, 0 },
                { 1, 0, 1 }
            };

            Console.WriteLine("The input matrix is as shown below:");
            MatrixProblemHelper.PrintMatrix(mat);
            Console.WriteLine("The max square is at {0}", mr.GetMaxRectArea(mat));
        }
예제 #2
0
        public static void TestPrintMatrixInSpiral()
        {
            int[,] mat = MatrixProblemHelper.CreateMatrix(4, 4);
            MatrixProblemHelper.PrintMatrix(mat);

            Console.WriteLine("The matrix spirally is as shown below:");
            Print(mat);

            mat = MatrixProblemHelper.CreateMatrix(3, 2);
            MatrixProblemHelper.PrintMatrix(mat);

            Console.WriteLine("The matrix spirally is as shown below:");
            Print(mat);

            mat = MatrixProblemHelper.CreateMatrix(2, 3);
            MatrixProblemHelper.PrintMatrix(mat);

            Console.WriteLine("The matrix spirally is as shown below:");
            Print(mat);

            mat = MatrixProblemHelper.CreateMatrix(3, 3);
            MatrixProblemHelper.PrintMatrix(mat);


            Console.WriteLine("The matrix spirally is as shown below:");
            Print(mat);

            mat = MatrixProblemHelper.CreateMatrix(3, 4);
            MatrixProblemHelper.PrintMatrix(mat);


            Console.WriteLine("The matrix spirally is as shown below:");
            Print(mat);
        }
예제 #3
0
        public static void TestRotateMatrix()
        {
            Rotate_Matrix_90_degree rtMat = new Rotate_Matrix_90_degree();

            int[,] mat = MatrixProblemHelper.CreateMatrix(4, 4);
            MatrixProblemHelper.PrintMatrix(mat);
            Console.WriteLine();
            mat = rtMat.RotateMatrix(mat);
            MatrixProblemHelper.PrintMatrix(mat);
        }
예제 #4
0
        public static void TestRotateMatrix180()
        {
            int[,] mat = MatrixProblemHelper.CreateMatrix(4,5);
            Console.WriteLine("The actual matrix");
            MatrixProblemHelper.PrintMatrix(mat);

            Console.WriteLine("Rotate matrix 180 degree");
            RotateMatrix180 rotateMat = new RotateMatrix180();
            rotateMat.RotateMatrix180Degree(mat);
            MatrixProblemHelper.PrintMatrix(mat);
        }
예제 #5
0
        public static void TestWaterfallCreation()
        {
            float[,] area = new float[, ]
            {
                { 0, 0, 50, 0, 0 },
                { 0, -1, -1, -1, 0 },
                { -1, 0, 0, 0, -1 },
                { 0, -1, 0, -1, 0 },
            };
            MatrixProblemHelper.PrintMatrix(area);
            area = GetWaterFallVolumes(area);
            Console.WriteLine("The water fall volume is as shown below:");
            MatrixProblemHelper.PrintMatrix(area);

            area = new float[, ]
            {
                { 0, 0, 50, 0, 0 },
                { 0, -1, -1, -1, -1 },
                { -1, -1, -1, -1, 0 },
                { 0, -1, 0, -1, 0 },
            };
            MatrixProblemHelper.PrintMatrix(area);
            area = GetWaterFallVolumes(area);
            Console.WriteLine("The water fall volume is as shown below:");
            MatrixProblemHelper.PrintMatrix(area);

            area = new float[, ]
            {
                { 0, 0, 50, 0, 0 },
                { 0, -1, -1, -1, -1 },
                { -1, -1, -1, -1, 0 },
                { -1, -1, 0, -1, -1 },
            };
            MatrixProblemHelper.PrintMatrix(area);
            area = GetWaterFallVolumes(area);
            Console.WriteLine("The water fall volume is as shown below:");
            MatrixProblemHelper.PrintMatrix(area);

            area = new float[, ]
            {
                { 0, 0, 50, 0, 0 },
                { 0, -1, -1, -1, -1 },
                { -1, -1, -1, -1, 0 },
                { -1, -1, -1, -1, -1 },
                { -1, 0, 0, -1, -1 },
            };
            MatrixProblemHelper.PrintMatrix(area);
            area = GetWaterFallVolumes(area);
            Console.WriteLine("The water fall volume is as shown below:");
            MatrixProblemHelper.PrintMatrix(area);
        }
        public static void TestSumOfMatrixElements()
        {
            int[,] mat = MatrixProblemHelper.CreateMatrix(4, 5);
            Console.WriteLine("The actual matrix");
            MatrixProblemHelper.PrintMatrix(mat);

            Console.WriteLine("Sum of matrix elements in the rectangle");
            SumOfMatrixElementsFormedByRectangleWithCoordinates sumMat = new SumOfMatrixElementsFormedByRectangleWithCoordinates();

            mat = sumMat.PreProcessMatrix(mat);
            MatrixProblemHelper.PrintMatrix(mat);

            Console.WriteLine("the area is: " + sumMat.GetArea(2, 2, 3, 4, mat));
        }
        public static void TestMakeRowColZero1()
        {
            int[,] mat = MatrixProblemHelper.CreateMatrix(4, 5);
            // Make a few places 0
            Random rnd = new Random();

            mat[rnd.Next(0, 4), rnd.Next(0, 5)] = 0;
            mat[rnd.Next(0, 4), rnd.Next(0, 5)] = 0;
            Console.WriteLine("original matrix");
            MatrixProblemHelper.PrintMatrix(mat);
            Console.WriteLine();

            Console.WriteLine("all affected rows and columns are 0 using Algorithm 1");
            mat = MakeRowColZero1(mat);
            MatrixProblemHelper.PrintMatrix(mat);
        }
        public static void TestSortedArrayFromSortedMatrix()
        {
            int[,] mat = new int[, ] {
                { 1, 2, 5 }, { 3, 6, 10 }, { 4, 20, 28 }
            };
            MatrixProblemHelper.PrintMatrix(mat);
            SortedArrayFromSortedMatrix sm = new SortedArrayFromSortedMatrix(mat);

            Console.WriteLine("the sorted array is as shown below:");
            ArrayHelper.PrintArray(sm.SortedArray);

            mat = new int[, ] {
                { 1, 2, 5 }, { 3, 6, 10 }, { 4, 20, 28 }, { 4, 20, 28 }
            };
            MatrixProblemHelper.PrintMatrix(mat);
            sm = new SortedArrayFromSortedMatrix(mat);
            Console.WriteLine("the sorted array is as shown below:");
            ArrayHelper.PrintArray(sm.SortedArray);
        }