diff --git a/src/main/java/com/thealgorithms/divideandconquer/QuickSort.java b/src/main/java/com/thealgorithms/divideandconquer/QuickSort.java new file mode 100644 index 000000000000..a5d10de928f0 --- /dev/null +++ b/src/main/java/com/thealgorithms/divideandconquer/QuickSort.java @@ -0,0 +1,49 @@ +import java.util.Arrays; +package com.thealgorithms.divideandconquer; + +//Java Program to Implement Quick Sort Algorithm for Sorting + +/* + * Uses Divide and Conquer Approach for Sorting + * Time Complexity: O(nlogn) as an average case and O(n^2) for the worst case (Sorted Array) + * Space Complexity: O(n) + * + * Reference: + * https://www.geeksforgeeks.org/quick-sort-algorithm/ +**/ +public class QuickSort +{ + //Function to find Partition Index + public static int partition(int []arr, int start, int end) + { + int pivot = arr[end]; + int index = start-1; + //Dividing Array into 2 parts where left of partition index is all values less than it and right of it all values more than it + for(int i=start; i<=end-1;i++) + { + if(arr[i]