• Home
  • University of the People
  • Data Structures (proctored course) CS 3303
  • Quicksort Algorithm Implementation and Analysis

Quicksort Algorithm Implementation and Analysis

Programming Assignment Unit 6 University of the People CS 3033 - Data Structure and Algorithms Instructor: Madhukeshwar Khanapur July 27, 2023 Algorithm Description: For this assignment, I have implemented the Quicksort algorithm to sort an array of integers containing 21 random items. The chosen algorithm divides the array into smaller subsets and efficiently sorts them by selecting a pivot element. The pivot selection is crucial to the performance of Quicksort. The algorithm recursively sorts the subsets until the entire array is sorted. Asymptotic Analysis: Utilizing Asymptotic notation, notably Big O, which represents the upper bound of the Quicksort method's temporal complexity, the effectiveness of the algorithm is examined. Although Quicksort typically performs far better and has a time complexity of O(n log n), its worst-case time complexity is O(n2). The effectiveness of Quicksort is substantially impacted by the pivot selection approach. In order to prevent the worst-case scenario, the implementation uses the median of three pivot selections. My Implementation: Below is the code for the Quicksort algorithm I have implemented in Java: public class QuicksortExample { public static void quickSort(int array[], int low, int high) { if (low < high) { int pivotIndex = partition(array, low, high); quickSort(array, low, pivotIndex - 1); quickSort(array, pivotIndex + 1, high); } } public static int partition(int array[], int low, int high) { int pivot = array[high]; int i = low - 1; for (int j = low; j < high; j++) { if (array[j] <= pivot) { i++; int temp = array[i]; array[i] = array[j]; array[j] = temp; } } int temp = array[i + 1]; array[i + 1] = array[high]; array[high] = temp; return i + 1; } public static void main(String a[]) { int[] arr1 = {12, 9, 4, 99, 120, 1, 3, 10, 23, 45, 75, 69, 31, 88, 101, 14, 29, 91, 2, 0, 77}; System.out.println("Printing unsorted array before Quicksort"); for (int i : arr1) { System.out.print(i+""); }