Question: Implement Randomized-Hire-Assistant (A) method using Permute-By-Sorting This is what I have so far. import java.util.concurrent.ThreadLocalRandom; public class Lab06 { public static int[] RandomizedHireAssistant(int[]A){ int n=

Implement Randomized-Hire-Assistant (A) method using Permute-By-Sorting

This is what I have so far.

import java.util.concurrent.ThreadLocalRandom;

public class Lab06 {

public static int[] RandomizedHireAssistant(int[]A){

int n= A.length;

int best=0;

int hirecount=0;

for (int i=0;i

{

if(best==0 || i> best)

{

best=i;

hirecount++;

}

}

return A;

}

public static int Random(int a,int b)

{

int randomnumber= ThreadLocalRandom.current().nextInt(a,b);

return randomnumber;

}

public static int[] PermutebySorting(int[] A)

{

int n=A.length;

int [] P= new int[n] ;

int cube=n*n*n;

for(int i=0;i

{

P[i]=Random(i,cube);

}

for(int i=0; i

{

int min=i;

//find smallest priority candidate

for(int j=i+1;j

{

if(P[j]< P[min])

{

min=j;

}

//swap A

int temp=A[min];

A[min]=A[i];

A[i]=temp;

//swap P

temp=P[min];

P[min]=P[i];

P[i]=temp;

}

}

return A;

}

public static void main(String[] args)

{

int list[]={1,2,3,4};

System.out.println(RandomizedHireAssistant(PermutebySorting(list)));

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!