subject

Below is the pseudocode for Quicksort and Partition. As usual with recursive functions on arrays, we see the array indices s and e as arguments. Quicksort(A, s, e) sorts the part of the array between s and e inclusively. The initial call (that is, to sort the entire array) is Quicksort(A, 0, n − 1).
QuickSort(A, s, e)
if s < e
p = Partition (A, s, e) // Partition the array and return the position of pivot after the partition
QuickSort(A, s, p-1) // Sort left side
QuickSort (A, p+1, e) // Sort right side
end if
Partition(A, s, e)
pivot = A[s], i = s + 1, j = e; // Let the leftmost element be the pivot
while i<=j // Rearrange elements
while i < e & A[i] < pivot,
i = i + 1
end while
while j > s & A[j] >= pivot,
j = j - 1
end while
if i >= j
break
end if
swap A[i] nd A[j]
end while
swap A[s] nd A[j]
return j; // Return the index of pivot after the partition
Questions:
A) How do you modify Partition(A, s, e) so that it chooses the pivot as the median of three elements randomly selected from the array?
B) How do you modify Partition(A, s, e) so that it always chooses the pivot uniformly at random from the array (instead of shuffling the array initially)?

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 07:30
What is the original authority for copyright laws
Answers: 1
question
Computers and Technology, 24.06.2019 17:50
Create a class hand in its own module. one object of class hand represents a hand of cards and so one object stores a number of card objects. for this assignment you will submit three separate modules, one with the definition of class card, one with the definition of class hand and one with the main application that thoroughly tests class hand.class hand must contain the following four methods: 1) , numcardsinhand) takes an integer as parameter and initializes a hand object with numcardsinhand card objects inside it. these card objects are generated randomly. for simplicity, assume an infinite number of decks of cards.2) bjvalue(self) returns the blackjack value for the whole hand of cards3) ) returns a string containing all the cards in the hand4) hitme(self) adds one randomly generated card to the handcreate a main program in its own module that thoroughly tests class hand. you will have three modules/files to upload to your etudes assignment submission: card.py, hand.py and the module that contains your main program.two alternatives for extra credit - you cannot get credit for both! (+1 point): after you have thoroughly tested the class hand and all of its methods, add code to your main program that stores one hand object as a pickle file and reads it back into a new hand object. you are only eligible for this extra credit if class hand has all four of the methods above working.or(+2 points): after you have thoroughly tested the class hand and all of its methods, add code to your main program that stores one hand object as a text file on the disk and reads it back into a new hand object. you are only eligible for this extra credit if class hand has all four of the methods above working.notes: -start by making any and all modifications suggested by my comments to your previous submission of class card from assignment #6 "a robust card object"-once your class card is tested and working well, you will not make any further modifications to it for the purposes of class hand.-you can keep the test code for class card intact. if it is indented inside an if __name__ == "__main__", then it will not be executed when your main program's module imports it.-to save time, write and test one method for class hand at a time.-under no circumstances are you to attempt the extra credit until you are completely finished with writing and testing all the methods in class hand.
Answers: 3
question
Computers and Technology, 24.06.2019 21:00
How does a vaccine prevent sickness and individual?
Answers: 2
question
Computers and Technology, 25.06.2019 04:30
The word window is an example of a /an
Answers: 1
You know the right answer?
Below is the pseudocode for Quicksort and Partition. As usual with recursive functions on arrays, we...
Questions
question
History, 02.08.2019 11:00
question
Mathematics, 02.08.2019 11:00