Question

Assume that you run quicksort on n≥7 elements. What is the probability that the 5th and...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In the first case we want to calculate the probability of 5th and 7th smallest number to get compared . This would be possible only if they are on the same side and one of them becomes a pivot. But they would get separated if 6th smallest element becomes a pivot. Therefore total favourable conditions = 2 , unfavorable conditions = 1 .Total condition is 3. Hence probability = ​​​​​​​2/3

Running quicksort for three elements , three cases possible

case 1. Smallest element gets selected . Two comparisons and two elements are on the right side . Now one more comparison between them . Total comparison is 3

Case 2. Largest element is selected . 2 comparison in the starting and then all the elements come on left side and there is one more comparison between them . Total comparison is 3

Case 3. Middle element is selected . First two comparisons take place . Now elements are on either side . Therefore no other comparison possible. Total comparison is 2

Average =(3+3+2)/3 = ​​​​​​​8/3

Add a comment
Know the answer?
Add Answer to:
Assume that you run quicksort on n≥7 elements. What is the probability that the 5th and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Walk through the operation of QuickSort when n = 7 and the input array is A...

    Walk through the operation of QuickSort when n = 7 and the input array is A = (11, 13, 12, 32, 31, 33, 20). (a) Count the number of comparisons in the walk through. using LAST ELEMENTS (LAST ANSWER WAS NOT USING LAST ELEMENT AS PIVOT) (b) Evaluate 7!, lg(7!) and 7 x lg(7). (c) Construct a best-case example for QuickSort with n = 15.

  • 1.)What are the major properties of quicksort? 2.)Is quicksort considered stable and adaptive? 3.)What is the...

    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.

  • (Quicksort) Here is an array which has just been partitioned by the first step of quicksort:...

    (Quicksort) Here is an array which has just been partitioned by the first step of quicksort: 3, 0, 2, 4, 5, 8, 7, 6, 9. Which of these elements could have been the pivot? (List all possibilities and explain your answers.)

  • Suppose the quicksort program shown uses a partition function that always picks a[m] as the 5B....

    Suppose the quicksort program shown uses a partition function that always picks a[m] as the 5B. 2M separator v. When the array a[m],....a[n] is reordered, assume that the order is preserved as much as possible. That is, first come all the elements less than v, in their original order, then all elements equal to v, and finally all elements greater than v, in their original order. int a[11]; void readArray0 {/* Reads 9 integers into int I; void quicksort( int...

  • 4.3 Assume that values have been assigned to all the elements of playland play2. Also assume...

    4.3 Assume that values have been assigned to all the elements of playland play2. Also assume that an int variable trickyhas been declared and intialised to 0. Use nested forloops and write down the necessary C++ statements to do the following: Each row of playlis compared element by element to the corresponding row of play2. If the elements are equal, add the value of one element to tricky. If the elements are not equal, add the sum of the two...

  • Data Structure Question. I need help solving this question. I know quicksort has the worst case...

    Data Structure Question. I need help solving this question. I know quicksort has the worst case of O(n^2) if it is implemented choosing the pivot as the first element. A[1] is the first element here. Please justify why the number of comparison is the smallest possible number assuming the array ensures that. And give an example of that type of an array. Thank you thumbs up will be given for correct and justified answer! qs(A): if A has at most...

  • In java 0 0 1 Hạshing Lab 1. Given the following key values, show what the...

    In java 0 0 1 Hạshing Lab 1. Given the following key values, show what the data structures would look like after insertions 27 53 13 10 138 109 49 174 26 24 (no preprocessing necessary: pk=key) a. Linear array of 10 elements using division hashing b. Bucket hashing of 10 elements (N=10) and the linear-quotient collision path algorithm ip = (px) %N N= 13, 4k+3 prime = 19 Array: Array: LOHashing: 1. ip = pk %N 1 2 2....

  • Please answer the following questions. Thanks! 1. A BST is created (it is initially empty) where...

    Please answer the following questions. Thanks! 1. A BST is created (it is initially empty) where the key associated with the data in each node is an integer. Elements are added to the BST with these keys in this order: 5, 4, 8, 7, 6, 9, 3, 2, 1. (a) Draw the resulting BST. (b) What is the height of the tree? 2. Continuing, assume the keys of Exercise 5.6 are integers which are appened to a linked list of...

  • 7. (20 points) Assume L is a list, and assume that int n=L length() returns the number of element...

    7. (20 points) Assume L is a list, and assume that int n=L length() returns the number of elements in the list, and Bubblsort(L, 0,i) sorts the list from 0 to i usin the g the Bubble sort algorithm. Determine asymtotic running time as function of n, e(T(n), for the average case time for the following code fragments a) for( int i = 1;i < n; i* 2) Bubblsort (L,0,i); for( int i=0;i 7. (20 points) Assume L is a...

  • 3 Quicksort 10 points (5 points each) 1. Suppose that you are given an array A[1..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)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT