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, 22.06.2019 15:20
The north and south regions had very diferent economies in the 1800s.
Answers: 1
question
Computers and Technology, 22.06.2019 23:30
Which text format is this, "the text is transcribed exactly as it sounds and includes all the utterances of the speakers. "?
Answers: 2
question
Computers and Technology, 23.06.2019 11:00
What is the name of the sound effect that danny hears
Answers: 1
question
Computers and Technology, 23.06.2019 13:00
Which of the following statements is false? a. a class can directly inherit from class object. b. if the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly. c. a class's instance variables are normally declared private to enforce good software engineering. d. it's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires.
Answers: 3
You know the right answer?
Below is the pseudocode for Quicksort and Partition. As usual with recursive functions on arrays, we...
Questions
question
Mathematics, 15.12.2020 01:00
question
Mathematics, 15.12.2020 01:00
question
Mathematics, 15.12.2020 01:00
question
Social Studies, 15.12.2020 01:00
Questions on the website: 13722361