subject

Below is the pseudocode for Quicksort and Partition that we talked about in class. 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

a)Let A = {11, 7, 6, 48, 30, 12, 75}, and assume we call Quicksort(A, 0, 6). Show what happens during the first invocation of Partition. What is the value of p returned, and what are the two recursive calls made?
Note: Credit will not be given only for answers - show all your work:

(5 points) steps you took to get your answer.

(2 points) your answer.

b)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?
(3 points) pseudocode to change Partition.

c)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)?
(2 points) pseudocode to change Partition.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 20:30
To display data in a certain manner like alphabetical order is called
Answers: 1
question
Computers and Technology, 22.06.2019 21:40
Develop a function to create a document in the mongodb database “city” in the collection “inspections.” be sure it can handle error conditions gracefully. a. input -> argument to function will be set of key/value pairs in the data type acceptable to the mongodb driver insert api call b. return -> true if successful insert else false (require a screenshot)
Answers: 2
question
Computers and Technology, 22.06.2019 22:00
What is a distinguishing feature of today’s graphic application software?) graphic applications are used today on a variety of devices, including touch-screen kiosks and mobile phones.
Answers: 3
question
Computers and Technology, 23.06.2019 06:00
Which statement is true of web-based social media? a.they allow consumers to interact with and update content. b.they cannot be updated easily, as compared to print media. c.they are expensive to produce and maintain, as compared to print and television. d.they can exist independent of the internet.
Answers: 1
You know the right answer?
Below is the pseudocode for Quicksort and Partition that we talked about in class. As usual with rec...
Questions
question
Mathematics, 29.01.2021 03:30
question
Mathematics, 29.01.2021 03:30
question
Mathematics, 29.01.2021 03:30
question
Mathematics, 29.01.2021 03:30
Questions on the website: 13722361