Menu

[Solved]4 Suppose Array 100 Numbers Intersted Finding Kth Smalest Number Instance Want 27th Smalle Q37075882

4. Suppose you have an array of 100 numbers. You are intersted in finding the kth smalest number. For instance you want the 24. Suppose you have an array of 100 numbers. You are intersted in finding the kth smalest number. For instance you want the 27th smallest number. At first you think that the best way to find this number is to sort the data and index into the array at the 27th location. Clearly the complexity of this would be the complexity to sort the data, typically nlnn for Quicksort for instance. But then you think that it is possible that Partition will by chance place the first pivot element into the 27th location. Not likely, as the likelihood is 1/100. However consider case 1, if partition places the pivot into the 35th location, then the element you are searching for is the 27th element in an array of 34 elements. In case 2, if the pivot is placed into the 19th location, then the element you are searching for is the 8th element of an array of 81 elements. In case we need to continue with the left part of the array only, but in case 2, we need to continue with the right part of the array only. This is a modified Quicksort algoithm (a) Write the pseudocode for this algorithm (b) Determine the recurrence for the algorithm and solve its complexity Show transcribed image text 4. Suppose you have an array of 100 numbers. You are intersted in finding the kth smalest number. For instance you want the 27th smallest number. At first you think that the best way to find this number is to sort the data and index into the array at the 27th location. Clearly the complexity of this would be the complexity to sort the data, typically nlnn for Quicksort for instance. But then you think that it is possible that Partition will by chance place the first pivot element into the 27th location. Not likely, as the likelihood is 1/100. However consider case 1, if partition places the pivot into the 35th location, then the element you are searching for is the 27th element in an array of 34 elements. In case 2, if the pivot is placed into the 19th location, then the element you are searching for is the 8th element of an array of 81 elements. In case we need to continue with the left part of the array only, but in case 2, we need to continue with the right part of the array only. This is a modified Quicksort algoithm (a) Write the pseudocode for this algorithm (b) Determine the recurrence for the algorithm and solve its complexity

Expert Answer


Answer to 4. Suppose you have an array of 100 numbers. You are intersted in finding the kth smalest number. For instance you want … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *