1.)What are the major properties of quicksort?
2.)Is quicksort considered stable and adaptive?
3.)What is the worst case number of comparisons and number of swaps for quicksort? Provide the Big-O notation for the mathematical function for quicksort worst case.
4.)What is the average case number of comparisons and number of swaps for quicksort? Provide the Big-O notation for the mathematical function for quicksort average cases.
1)
2)
No, quicksort is considered an unstable algorithm.
3)
Worst Case input for maximum number of swaps will be already sorted array in decreasing order.
Recurrence for Total number of swaps in this case :
T(n) = T(n-1) + O(n) // O(n) swaps will occur in alternate calls to
partition algorithm.
= O(n2)
Similarly, the worst case of comparisons takes place when the array is sorted in the reverse order.
Number of comparisons = O(n2)
NOTE: As per HOMEWORKLIB POLICY, I am allowed to answer only 3 questions (including sub-parts) on a single post. Kindly post the remaining questions separately and I will try to answer them. Sorry for the inconvenience caused.
1.)What are the major properties of quicksort? 2.)Is quicksort considered stable and adaptive? 3.)What is the...
Assume that you run quicksort on n≥7 elements. What is the probability that the 5th and 7th smallest elements are compared? 1) 0 2) 1/4 3) 1/3 4) 1/2 5) 2/3 6) 3/4 7) 1 Assume that you run quicksort on 3 elements. What is the average number of comparisons? 1) 2 2) 9/4 3) 7/3 4) 5/2 5) 8/3 6) 11/4 7) 3
Consider the array a = {3, 5, 2, 6, 0, 2, 1} Trace the execution of QuickSort(a). What is the best, average, and worst-case time complexity of QuickSort?
Exercise 1 Use Top-Down Design to “design” a set of instructions to write an algorithm for “travel arrangement”. For example, at a high level of abstraction, the algorithm for “travel arrangement” is: book a hotel buy a plane ticket rent a car Using the principle of stepwise refinement, write more detailed pseudocode for each of these three steps at a lower level of abstraction. Exercise 2 Asymptotic Complexity (3 pts) Determine the Big-O notation for the following growth functions: 1....
[Code in C] Help me with this. Not sure what to do. 1 Couting Sort You may have learned some sorting algorithms - such as bubble sort ad quicksort in CS 110 and CS 210. This homework is about counting sort. Let n be the number of elements to be sorted. Bubble sort and quicksort assume tha time, which one is larger and which one is smaller. They make no assumption on the values of the elements t we can...
Subject: Algorithm. solve only part 3 and 4 please. 2.2 Selection- 5 points each 1. Run the simultaneous min-and-max algorithm on the array A 4, 2, 12, 6, 13,9,15). (16, 7, 10, 1,5, 11,3,8, 14, 2. Explain why the above algorithm is better than the naive algorithm for finding minimum and maximum separately. How many comparisons does the naive algorithm do? How many comparisons does the simultaneous min and max do? 3. Use the randomized select algorithm based on partition...
Question 3: Given the following two code fragments [2 Marks] (i)Find T(n), the time complexity (as operations count) in the worst case? (ii)Express the growth rate of the function in asymptotic notation in the closest bound possible. (iii)Prove that T(n) is Big O (g(n)) by the definition of Big O (iv)Prove that T(n) is (g(n)) by using limits
4 Let the set of all possible keys considered is the set of all integers from 0 to 10,000 inclusive. Consider a closed hashing and a hash table of size M 10 and the hash function h(x) xmod 10. Note: Using a prime number as the size of the table is not a good idea. However, we do so to keep the calculations simple. a) Write an algorithm (using any programming language) to find the largest value in this hash...
Question 3 (1 point) What is NOT a major type of derivatives Options Futures Hedge funds Swaps Question 4 (1 point) How large is the derivatives market in terms of notional outstanding? Pick the closest number $60 trillion O $600 billion O $600 trillion O $6,000 trillion
2.What is the order of complexity of the insert function in the worst case? You are required to provide a complexity function, and a proof that your complexity function belongs to a particular complexity class. In your complexity function you may specify the number of comparisons performed, as a function of input size. def insert(element, sorted): if len(sorted) == 0: return [element] else: if sorted[0] >= element: new_copy = sorted[:] new_copy.insert(0, element) return new_copy else: return [sorted[0]] + insert(element, sorted[1:])
Problem 1. 1. Draw the decision tree for the merge-sort algorithm for the input consisting of 3 numbers: a, b,c. 2. Draw the 4 top levels of the decision tree for the merge-sort algorithm for the input consisting of 4 numbers: a, b, c, d 3. How may leaves does this tree have? 4. How many levels does this tree have? 5. What is the number of comparisons needed to sort these 4 numbers by the merge-sort algorithm in the...