Question

In: Computer Science

Assume the following list of keys: 78, 40, 16, 82, 64, 67, 57, 40, 37, 47,...

Assume the following list of keys:

78, 40, 16, 82, 64, 67, 57, 40, 37, 47, 72, 14, 17, 27, 55

This list is to be sorted using the quick sort algorithm as discussed in this chapter. Use pivot as the median of the first, last, and middle elements of the list.

  1. What is the pivot?
  2. Give the resulting list after one call to the partition function.

Solutions

Expert Solution

According to the problem statement,

The answers are as follows,

a) What is the pivot?

Answer: 55

Explanation:

  • According to the rules of QuickSort, a pivot element can be the first element or can be a middle element or it can be last element or any random element from the array.
  • But as a standard practise, most of the people will take last element of the array as PIVOT
  • So, the pivot element is 55
  • As you said first and last and middle elements, the pivot's are first = 78, middle = 40, last = 55

b) Give the resulting list after one call to the partition function?

Answer: 40, 16, 40, 37, 47, 14, 17, 27, 55, 64, 72, 67, 57, 78, 82

Explanation:

  • According to the QuickSort rules, partition function will take arr, low and high elements as the parameters.
  • low is the starting index of array 0
  • high is the index of length-1        n-1
  • After one call to the partition, the result will be like and the pivot 55 will gets its original place after whole sort.

I hope the above information and explanation will help you out!

Please comment if you have any queries/errors!

Thank you!


Related Solutions

x 37 47 57 67 77 87 y 5 8 10 14 31 45 Complete parts,...
x 37 47 57 67 77 87 y 5 8 10 14 31 45 Complete parts, given Σx = 372, Σy = 113, Σx2 = 24814, Σy2 = 3371, Σxy = 8371, and r ≈ 0.926. a) Verify the given sums Σx, Σy, Σx2, Σy2, Σxy, and the value of the sample correlation coefficient r. (Round your value for r to three decimal places.) Σx = Σy = Σx2 = Σy2 = Σxy = r = b) Find x, and...
You have been given the following set of keys 12, 45, 1, 9, 67, 230, 78,...
You have been given the following set of keys 12, 45, 1, 9, 67, 230, 78, 64, 450, 436, 123, 6, 12, 90 Use insertion to sort the elements in ascending and descending order ( show the steps)     [5 Marks] Using heaps, show how the keys can be sorted in ascending and descending order ( show the steps)      [5 Marks] Using Big O, derive the space and time complexity of insertion sort and heap sort algorithms above
Consider the following list of ages. 72, 64, 82, 81, 84, 51, 81, 64, 75, 53,...
Consider the following list of ages. 72, 64, 82, 81, 84, 51, 81, 64, 75, 53, 98, 78, 71, 35, 99, 88, 82, 52, 74, 86, 88, 74, 94, 80, 52, 76, 70, 74, 64, 83, 95 (a) Create a five-number summary for these ages. Lowest Value Lowest quartile Median Highest quartile Highest value (b) Create a boxplot using the five-number summary from part (a). The box-and-whisker plot has a horizontal axis numbered from 30 to 100. The box-and-whisker is...
Use Statkey for the following numbers: 18 54 64 46 91 38 25 45 67 57...
Use Statkey for the following numbers: 18 54 64 46 91 38 25 45 67 57 48 44 63 83 84 79 52 54 41 52 56 76 41 75 79 68 28 55 77 68 33 65 59 37 61 70 47 51 32 56 19 45 29 63 75 39 84 48 42 36 1. Does this data come from a "mound-shaped", distribution? Justify your answer. 2. Is the data symmetric or skewed? Justify your answer. 3. Are...
int[]array1={67, 78, 92, 45, 67, 86, 24, 96, 39, 82, 86}; String[] array2 ={“Namath”, “Dockery”, “Atkinson”,...
int[]array1={67, 78, 92, 45, 67, 86, 24, 96, 39, 82, 86}; String[] array2 ={“Namath”, “Dockery”, “Atkinson”, “Sauer”, “Brady”, “Maynard”, “Boozer”}; Write code using selection sort to sort array1 in descending order Write code using selection sort to alphabetize array2. Write a method called cubicNumbers that will sum the 3rd power of each of first n positive integers cublic powers . Example cubicNumbers(4)-> 43 + 33+23 +13 =64+27+8+1=100. Write this code in an iterative fashion Write a method called cubicNumbers that...
Given the data set below 25 52 67 23 78 89 57 90 32 77 45...
Given the data set below 25 52 67 23 78 89 57 90 32 77 45 48 62 54 94 69 46 79 40 33 21 57 84 54 23 34 68 63 61 76 87 78 39 50 70 60 32 65 73 45 28 82 66 79 71 80 46 66 24 90 A)What is the probability of an impossible even? B) What is the probability of a certain event? C) find the approximate mean using the Frequency...
Population 1 59 57 77 60 59 64 72 67 Population 2 61 53 84 53...
Population 1 59 57 77 60 59 64 72 67 Population 2 61 53 84 53 69 74 64 73 Can it be concluded, from this data, that there is a significant difference between the two population means? Let d=(Population 1 entry)−(Population 2 entry)d=(Population 1 entry)−(Population 2 entry). Use a significance level of α=0.01α=0.01 for the test. Assume that both populations are normally distributed. 1.State the null and alternative hypotheses for the test 2. Find the value of the standard...
int[]array={90, 57, 34, 81, 59, 51, 99, 52, 78, 67}; use for numbers 1 through 4...
int[]array={90, 57, 34, 81, 59, 51, 99, 52, 78, 67}; use for numbers 1 through 4 Write code to create two int arrays called odd and even of length 10. Populate the arrays with even numbers in the even array and odd numbers in the odd array as you go through the int[]array [ reminder 7%2 is 1, 8%2 is 0. The modulus operator yields the remainder]. Do not worry about the 0’s that are not filled. Write code to...
Find the lower fence for the following data set: 45, 34, 27, 78, 42, 64, 78...
Find the lower fence for the following data set: 45, 34, 27, 78, 42, 64, 78 Find the upper fence for the following data set: 3, 19, 47, 18, 23, 34, 45, 27, 10, 7
assume that a stock is selling for $47 with options available at 20, 30, and 40...
assume that a stock is selling for $47 with options available at 20, 30, and 40 strike price. The 30 call option is at 10 1/2. Calculate the following: A) The intrinsic value of the $40 call. B) Is the call in the money? c)The speculative premium on the 30 call option D) The percent the speculative premium represents of the common stock price
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT