public class Group3 { int sort(int arr[], int low, int high) { int p = arr[high]; int i = (l

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

public class Group3 { int sort(int arr[], int low, int high) { int p = arr[high]; int i = (l

Post by answerhappygod »

public class Group3{ int sort(int arr[], int low, inthigh) { int p =arr[high]; int i = (low-1); for (int j=low; j<high;j++) {
if(arr[j] <= p) { i++; int temp = arr; arr = arr[j]; arr[j] = temp; } }
int temp =arr[i+1]; arr[i+1] =arr[high]; arr[high] = temp;
return i+1; }
void XYZ(int arr[], int low, inthigh) {
if (low <high) { int pi =sort(arr, low, high);
XYZ(arr, low, pi-1); XYZ(arr,pi+1, high); } }
static void print(int arr[]) { int n =arr.length; for (int i=0; i<n;++i) System.out.print(arr+" "); System.out.println(); }
public static void main(Stringargs[]) { int arr[] = {45, 64, 87, 90,8, 98, 30, 9 }; int n = arr.length;
System.out.println("Beforesort"); print(arr); Group3 ob = newGroup3(); ob.XYZ(arr, 0,n-1);
System.out.println("Aftersort"); print(arr); } } 1. What is the output of the program? 2. Name the sorting algorithm used in the program and explain thesorting algorithm in detail on how it works with anexample. 3. Modify the code to support the following.a) Add a variable named countSwap of type integer with initialvalue 0.b) Count the number of swaps the above sorting algorithm takes.Please note the swaps are not the same as the number ofcomparisons.c) Explain briefly when the above algorithm performance becomeinefficient.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply