1. Quicksort will run fastest, when every time pivot element selected to partition the array has rank n/2 where n is the elements in the array whose pivot is selected. Hence oracle will return the element of rank n/2 as the pivot element.
If this happens, then array will be partitioned equally after each recursion and hence time complexity will be given by
T(n) = 2T(n/2) + O(n)
which solves to T(n) = O(n log n)
2. Given array A = {6,7,2,4,10,8,1,9} consisting of 8 elements, so the best pivot element to partition will be 6 since it has rank 4 in the sorted array.
Hence the element 6 will partition the array A as
2,4,1, 6, 7,10,8,9
Then in the left subarray, element 2 will be pivot and in right subarray element 8 will be pivot and the result will be
1, 2, 4, 6, 7, 8, 10,9
Here the rightmost subarray of 2 elements are not sorted and hence element 9 will be selected as pivot which will finally sort the array as
1,2,4,6,7,8,9,10
Please comment for any clarification.
3 Quicksort 10 points (5 points each) 1. Suppose that you are given an array A[1..n]...
HW60.1. Array Quicksort You've done partition so now it's time to finish Quicksort. Create a public non-final class named Quicksort that extends Partitioner. Implement a public static method void quicksort (int] values) that sorts the input array of ints in ascending order. You will want this method to be recursive, with the base case being an array with zero or one value. You should sort the array in place, which is why your function is declared to return void. If...
You want to sort (in increasing order) the following array of integers using quicksort as we have described it and used it in class. You are asked to specifically show your steps and the resulting array after one pass of quicksort. Show and explain each of your steps. Note 1: in case you are not using the algorithm presented and traced in class, you are expected to show all your steps accompanied with algorithm instructions and variables' values. Note 2:...
Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8 9 7 0 4 Pivot selection is defined to be the first element of each sub-list. Show the array before and after each quicksort round (when the array is partitioned after placing the pivot at its correct position). Also, clearly highlight the pivot in each partition b. Consider an unsorted array of integers of size n. Write a Java program to arrange the array...
soneoxderFor example: weotes 2. (15%) a) (5%) Given the following array [ 10, 5, 3, used to sort this array in ascending order select possible To 22, 24, 28, 27, 21 and assuming that Quicksort will be for the last element of the array 9 alue(S bysuch that the partitioning performed by Quicksort is most balanced Explain why this ae lstt elenern's makes Quicksort perform efficiently soneoxderFor example: weotes 2. (15%) a) (5%) Given the following array [ 10, 5,...
4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up to n, anda number num which we wish to insert into A, in the proper sorted position. The function Search finds the minimum index i such that num should be inserted into Ali]. It searches the array sequentially until it finds the location i. Another function MakeRoom moves A[i], .., AIn] to Ali+1]...AIn+1] same sort...
QUESTION 3 Suppose that you have been running an unknown sorting algorithm. Out of curiosity, you once stopped the algorithm when it was part-way done and examined the partially sorted array. You discovered that the last K elements of the array were sorted into ascending order, but the remainder of the array was not ordered in any obvious manner. Based on this, you guess that the sorting algorithm was (select all that apply): heapsort insertion sort mergesort quicksort Shell's sort...
5. Answer the following. (a) (5 points) Suppose you are given a maxheap of n unique numbers. Explain where will the smallest of these n numbers be located in the maxheap. Explain where will the second largest number be located on this maxheap. Please be specific. (b) (5 points) Suppose you are given an array A of n numbers, where all the elements of the array are already sorted in decreasing order. Is this a max-heap? Explain. (c) (5 points)...
You are given the following array A = {12, 1, 15, 3, 0, 35, 11, 40, 7}. Apply and trace the execution of one pass of QuickSort where we pick 12 as our pivot.
Note: when a problem has an array of real numbers, you cannot use counting sort or radix sort. For this problem, you are given a number t and an array A with n real numbers that are not sorted. Describe an algorithm that finds the t numbers in A that are closest to the median of A. That is, if A = {x1, . . . , xa) and xrn is the median, we want to find the t...
2.1 Searching and Sorting- 5 points each 1. Run Heapsort on the following array: A (7,3, 9, 4, 2,5, 6, 1,8) 2. Run merge sort on the same array. 3. What is the worst case for quick sort? What is the worst case time com- plexity for quick sort and why? Explain what modifications we can make to quick sort to make it run faster, and why this helps. 4. Gi pseudocode for an algorithm that will solve the following...