Question textRecall the Hoare partitioning algorithm. We provide it below, as given in the course notes. [table] 1 2 3 4 5 6 7 8 9 10 11 12131415 | function PARTITION(array[lo..hi], array[p]) swap(array[lo], array[p]) print(array) // Added for demonstration i = lo + 1, j = hi while i ≤ j do while i ≤ j and array[i] ≤ array[lo] do i = i + 1 while i ≤ j and array[j] > array[lo] do j = j − 1 if i < j then swap(array[i], array[j]) i = i + 1 j = j − 1 print(array) // Added for demonstration swap(array[lo], array[ j ]) print(array) // Added for demonstration return j [/table] Given the input array [table] 9 | 7 | 4 | 10 | 4 | 1 | 3 | 8 | 2 | 6 [/table] Suppose we called PARTITION(array[1..10], array[5]). Give the contents of the array for each print on lines 3, 12 and 14 until the algorithm terminates. Additionally, you may find it useful to track the values of i and j in the two top boxes. No justification is required. Each horizontal row in the table below should correspond to a single print on line 3, 12 or 14. There should be exactly 5 lines printed throughout execution. [table] Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 Print 1: | Answer 3 Question 4 | Answer 4 Question 4 | Answer 5 Question 4 | Answer 6 Question 4 | Answer 7 Question 4 | Answer 8 Question 4 | Answer 9 Question 4 | Answer 10 Question 4 | Answer 11 Question 4 | Answer 12 Question 4 Print 2: | Answer 13 Question 4 | Answer 14 Question 4 | Answer 15 Question 4 | Answer 16 Question 4 | Answer 17 Question 4 | Answer 18 Question 4 | Answer 19 Question 4 | Answer 20 Question 4 | Answer 21 Question 4 | Answer 22 Question 4 Print 3: | Answer 23 Question 4 | Answer 24 Question 4 | Answer 25 Question 4 | Answer 26 Question 4 | Answer 27 Question 4 | Answer 28 Question 4 | Answer 29 Question 4 | Answer 30 Question 4 | Answer 31 Question 4 | Answer 32 Question 4 Print 4: | Answer 33 Question 4 | Answer 34 Question 4 | Answer 35 Question 4 | Answer 36 Question 4 | Answer 37 Question 4 | Answer 38 Question 4 | Answer 39 Question 4 | Answer 40 Question 4 | Answer 41 Question 4 | Answer 42 Question 4 Print 5: | Answer 43 Question 4 | Answer 44 Question 4 | Answer 45 Question 4 | Answer 46 Question 4 | Answer 47 Question 4 | Answer 48 Question 4 | Answer 49 Question 4 | Answer 50 Question 4 | Answer 51 Question 4 | Answer 52 Question 4 [/table] Please answer all parts of the question.多项填空题

登录即可查看完整答案
我们收录了全球超50000道真实原题与详细解析,现在登录,立即获得答案。
类似问题
Which of the following statements are true regarding Quicksort?
When QuickSort repeatedly produces highly skewed partitions (for example, the pivot always becomes the smallest or largest element), what is the resulting time complexity, given the explanations below?
Sorting Complexity For an array of N integers that are in the ascending order as shown below, give the time complexity for each sorting algorithm. 1,2,3, ... , N-2, N-1, N 1: Insertion Sort 2: Selection Sort 3: Bubble Sort 4: Merge Sort 5: Tree (BST) Sort (hint:Is BST very unbalanced?)
Sorting The following is the correct operation sequence of the _____________ sort. A. Input: 3 4 5 1 6 2 iteration 1: 3 4 1 5 2 6 iteration 2: 3 1 4 2 5 6 iteration 3: 1 3 2 4 5 6 iteration 4: 1 2 3 4 5 6 iteration 5: 1 2 3 4 5 6 B. Input: 3 4 5 1 6 2 iteration 1: 3 4 5 1 6 2 iteration 2: 3 4 5 1 6 2 iteration 3: 1 3 4 5 6 2 iteration 4: 1 3 4 5 6 2 iteration 5: 1 2 3 4 5 6 C: Input: 3 4 5 1 6 2 iteration 1: 1 4 5 3 6 2 iteration 2: 1 2 5 3 6 4 iteration 3: 1 2 3 5 6 4 iteration 4: 1 2 3 4 6 5 iteration 5: 1 2 3 4 5 6 1: A 2: B 3: C
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!