Given an specific example of a list of n integers where the
running time of
Quicksort on them is in Ω(n2). (Assume the pivot is always chosen
at the front of a
list.)
Quick Sort will have the worst performance of O(n^2) if the pivot chosen is either the the smallest or largest number. (This is because such a pivot will lead to nearly n recursions and the number of comparison in each recursion are of the order of n).
If pivot is chosen as front of list, then a sorted (or reverse sorted) list will lead to worst case complexity. (As the first element will be smallest or largest).
Given an specific example of a list of n integers where the running time of Quicksort...
What is the average running time for quicksort? O(1) O(log10N) O(log2N) O(log2N) O(N) O(N log N) O(N2) O(N3) O(Nk) O(2N) O(N!)
3 Quicksort 10 points (5 points each) 1. Suppose that you are given an array A[1..n] and that you want to sort it using quicksort. Further suppose that your algorithm could consult an oracle to predict what element to use as the pivot. Which element would it pick so that your algorithm would run as fast as possible? What is the running time given your pivot? 2. Run the partition algorithm to partition the array A (6,7,2,4, 10,8, 1,9)
Given the below array of integers, assume that quicksort chose the value '12' as the pivot value. Assuming we want to sort in ascending order, why is this a poor choice? int a[] = { 6, 12, 8, 2, 1, 7 }; Group of answer choices: it is the highest value in the array it is near the median value of the array it is less than 100 It is at the second position of the array
Implement quicksort and bucket sort. Use the code in your book to help; the partition in quicksort is tricky. Make sure your implementations are correct — it is easy to gain some confidence in the correctness of your code by writing a program which creates arrays filled with random numbers, sorts them, and then checks that they are sorted. Then time your code (using clock() or similar methods) on both methods for arrays filled with random integers of the following...
This part involves writing and testing code. You are to make an experiment with 3 sorting algorithms partially given on Blackboard: Insertion sort, Mergesort, Quicksort. First, create a positive integer array of 10000 (ten thousand) elements with random values in it. Then, run the algorithms on this array by recording their running times. That is, take note of the time just before the sorting starts, and just after the sorting finishes, and record the difference. For a complete experiment, do...
Consider the following Python program, where x is assumed to be a list of integers. def mystery_func(x): n = len(x) for i in range(n - 1): for j in range(i + 1, n): if x[j] - x[i] < j - i: return False return True 3a. In plain English, describe what it accomplishes (i.e., the relationship between input and output, not how the code works). 3b. Analyze the running time and express it with big O. 3c. Rewrite this function...
Analyze and prove the running time of the recursive formula T(n) = n2 + 2T(n/2). (hint- first prove that it is O(n2 logn). Next see if you could improve your answer. We used the recursion tree method to analyze the running time of MergeSort. Use this method to analyze each one of the following recursive formulas, and obtain its solution. Assume T(n) = 1 when n ≤ 1. Analyze and prove the running time of the recursive formula T(n) =...
You are given an array of integers, where different integers may have different numbers of digits but the total number of digits over all integers in the array is n. Show how to sort the array in increasing order in O(n) time. Note: The number of integers in the array can be different for same value of n - for example the array with 2 integers 2468 and 12345 has 9 digits as well as the array with 5 integers...
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)...
(13 pts) Given an array AlI,2,. .. ,n] integers, design and analyze an efficient Divide-and-Conquer algorithm to find some i and j, where j > 1, such that A[j]-Ali] is maximized. For example, given A 6, 1,3,8,4,5, 12,6], the maximum value of AL] - Ali] for j > i is 12-1 11 where j -7 and i 2. Give the underlying recurrence relation for your algorithm and analyze its running time. You should carefully state all details of your algorithm:...