From f66bf1ba75858cc66082e3c1510c3ed95b0ca9dd Mon Sep 17 00:00:00 2001 From: Sumana Datta Kapavarapu <137371757+git-sumana@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:02:56 +0530 Subject: [PATCH 1/4] Create test --- test | 1 + 1 file changed, 1 insertion(+) create mode 100644 test diff --git a/test b/test new file mode 100644 index 0000000..45b983b --- /dev/null +++ b/test @@ -0,0 +1 @@ +hi From affc6ab8387f09fdfe4223e2dd87ba4833b18dc8 Mon Sep 17 00:00:00 2001 From: Sumana Datta Kapavarapu <137371757+git-sumana@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:12:15 +0530 Subject: [PATCH 2/4] Add files via upload ### Radix Sort in Java This repository contains a Java implementation of Radix Sort, a non-comparative integer sorting algorithm. The `RadixSort.java` file includes the implementation of the algorithm. The `main` method demonstrates the sorting process with a sample array. Radix Sort has a time complexity of O(nk), where n is the number of elements and k is the number of digits in the largest number. --- Java/sorting/Radix.txt | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Java/sorting/Radix.txt diff --git a/Java/sorting/Radix.txt b/Java/sorting/Radix.txt new file mode 100644 index 0000000..7818c2a --- /dev/null +++ b/Java/sorting/Radix.txt @@ -0,0 +1,76 @@ +import java.util.Arrays; + +public class Radix { + + // A utility function to get the maximum value in arr[] + static int getMax(int arr[]) { + int max = arr[0]; + for (int i = 1; i < arr.length; i++) + if (arr[i] > max) + max = arr[i]; + return max; + } + + // A function to do counting sort of arr[] according to + // the digit represented by exp. + static void countSort(int arr[], int exp) { + int n = arr.length; + int output[] = new int[n]; + int count[] = new int[10]; + Arrays.fill(count, 0); + + // Store count of occurrences in count[] + for (int i = 0; i < n; i++) + count[(arr[i] / exp) % 10]++; + + // Change count[i] so that count[i] now contains + // actual position of this digit in output[] + for (int i = 1; i < 10; i++) + count[i] += count[i - 1]; + + // Build the output array + for (int i = n - 1; i >= 0; i--) { + output[count[(arr[i] / exp) % 10] - 1] = arr[i]; + count[(arr[i] / exp) % 10]--; + } + + // Copy the output array to arr[], so that arr[] now + // contains sorted numbers according to the current digit + for (int i = 0; i < n; i++) + arr[i] = output[i]; + } + + // The main function to that sorts arr[] using Radix Sort + static void radixSort(int arr[]) { + int max = getMax(arr); + + // Do counting sort for every digit. Note that instead + // of passing digit number, exp is passed. exp is 10^i + // where i is current digit number + for (int exp = 1; max / exp > 0; exp *= 10) + countSort(arr, exp); + } + + // A utility function to print an array + static void printArray(int arr[]) { + for (int i : arr) System.out.print(i + " "); + System.out.println(); + } + + // Driver code + public static void main(String[] args) { + int arr[] = {170, 45, 75, 90, 802, 24, 2, 66}; + System.out.println("Original array:"); + printArray(arr); + + radixSort(arr); + + System.out.println("\nSorted array:"); + printArray(arr); + } +} + +// Original array: +170 45 75 90 802 24 2 66 +// Sorted array: +2 24 45 66 75 90 170 802 From e6ec6c48f3e27a80d329785babbeb36159e340f3 Mon Sep 17 00:00:00 2001 From: Sumana Datta Kapavarapu <137371757+git-sumana@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:13:38 +0530 Subject: [PATCH 3/4] Delete test --- test | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test diff --git a/test b/test deleted file mode 100644 index 45b983b..0000000 --- a/test +++ /dev/null @@ -1 +0,0 @@ -hi From 0725d901f1111fd44437b173480ea129ca571db2 Mon Sep 17 00:00:00 2001 From: Sumana Datta Kapavarapu <137371757+git-sumana@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:44:03 +0530 Subject: [PATCH 4/4] Add files via upload Strassen's Algorithm for Matrix Multiplication Strassen's Algorithm is an efficient algorithm for matrix multiplication, known for its recursive divide-and-conquer approach. It reduces the number of recursive calls by computing matrix products using fewer multiplications compared to the standard matrix multiplication algorithm. The algorithm splits the matrices into smaller submatrices, recursively computes their products using Strassen's Algorithm, and then combines the results to obtain the final product matrix. This approach reduces the number of multiplications, improving the overall efficiency of matrix multiplication. --- .../Arrays/StrassensAlgorithm.txt | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Java/Data Structures/Arrays/StrassensAlgorithm.txt diff --git a/Java/Data Structures/Arrays/StrassensAlgorithm.txt b/Java/Data Structures/Arrays/StrassensAlgorithm.txt new file mode 100644 index 0000000..5f129e1 --- /dev/null +++ b/Java/Data Structures/Arrays/StrassensAlgorithm.txt @@ -0,0 +1,92 @@ +public class StrassensAlgorithm { + + public static int[][] multiply(int[][] A, int[][] B) { + int n = A.length; + int[][] C = new int[n][n]; + if (n == 1) + C[0][0] = A[0][0] * B[0][0]; + else { + int[][] A11 = new int[n / 2][n / 2]; + int[][] A12 = new int[n / 2][n / 2]; + int[][] A21 = new int[n / 2][n / 2]; + int[][] A22 = new int[n / 2][n / 2]; + + int[][] B11 = new int[n / 2][n / 2]; + int[][] B12 = new int[n / 2][n / 2]; + int[][] B21 = new int[n / 2][n / 2]; + int[][] B22 = new int[n / 2][n / 2]; + + split(A, A11, 0, 0); + split(A, A12, 0, n / 2); + split(A, A21, n / 2, 0); + split(A, A22, n / 2, n / 2); + + split(B, B11, 0, 0); + split(B, B12, 0, n / 2); + split(B, B21, n / 2, 0); + split(B, B22, n / 2, n / 2); + + int[][] M1 = multiply(add(A11, A22), add(B11, B22)); + int[][] M2 = multiply(add(A21, A22), B11); + int[][] M3 = multiply(A11, sub(B12, B22)); + int[][] M4 = multiply(A22, sub(B21, B11)); + int[][] M5 = multiply(add(A11, A12), B22); + int[][] M6 = multiply(sub(A21, A11), add(B11, B12)); + int[][] M7 = multiply(sub(A12, A22), add(B21, B22)); + + int[][] C11 = add(sub(add(M1, M4), M5), M7); + int[][] C12 = add(M3, M5); + int[][] C21 = add(M2, M4); + int[][] C22 = add(sub(add(M1, M3), M2), M6); + + join(C11, C, 0, 0); + join(C12, C, 0, n / 2); + join(C21, C, n / 2, 0); + join(C22, C, n / 2, n / 2); + } + return C; + } + + public static void split(int[][] P, int[][] C, int iB, int jB) { + for (int i1 = 0, i2 = iB; i1 < C.length; i1++, i2++) + for (int j1 = 0, j2 = jB; j1 < C.length; j1++, j2++) + C[i1][j1] = P[i2][j2]; + } + + public static int[][] add(int[][] A, int[][] B) { + int n = A.length; + int[][] C = new int[n][n]; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + C[i][j] = A[i][j] + B[i][j]; + return C; + } + + public static int[][] sub(int[][] A, int[][] B) { + int n = A.length; + int[][] C = new int[n][n]; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + C[i][j] = A[i][j] - B[i][j]; + return C; + } + + public static void join(int[][] C, int[][] P, int iB, int jB) { + for (int i1 = 0, i2 = iB; i1 < C.length; i1++, i2++) + for (int j1 = 0, j2 = jB; j1 < C.length; j1++, j2++) + P[i2][j2] = C[i1][j1]; + } + + public static void main(String[] args) { + int[][] A = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}; + int[][] B = {{17, 18, 19, 20}, {21, 22, 23, 24}, {25, 26, 27, 28}, {29, 30, 31, 32}}; + + int[][] C = multiply(A, B); + for (int i = 0; i < C.length; i++) { + for (int j = 0; j < C[0].length; j++) { + System.out.print(C[i][j] + " "); + } + System.out.println(); + } + } +}