Chapter 9 - Faster Sorting Methods (Mostly fixed ✅)

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Given the following array of 9 elements, trace one iteration of the quick sort algorithm. Use the pivot strategy by selecting the median of three elements, the first, middle and last. Assume the array is to be sorted in ascending order. 81 16 4 6 34 11 23 67 52 🚧🚧🚧

Answer is to long like 3 pages so here is the short answer: This is the sorted array below: 4, 6, 11, 16, 23, 34, *52*, 67, 81 *52*

The radix sort restricts the data that it sorts on.

True

You cannot use a recurrence relation to estimate the time efficiency of the recursive merge sort algorithm because there are two recursive calls in the method. 🚧🚧🚧

True

The average-case performance of quick sort for n items is a. O(n log n) b. O(log n) c. O(n) d. O(n2)

a. O(n log n)

The best-case performance of quick sort for n items is a. O(n log n) b. O(log n) c. O(n) d. O(n2)

a. O(n log n)

The performance of merge sort for n items is a. O(n log n) b. O(log n) c. O(n) d. O(n2)

a. O(n log n)

The average-case performance of radix sort on restricted data is a. O(n) b. O(log n) c. O(n log n) d. O(n2)

a. O(n)

In merge sort, the merge step takes at most ______ comparisons for n items. a. n - 1 b. n c. 2n d. n2

a. n - 1

In quick sort, dividing the array portions before and after the pivot are called a. partitions b. sections c. halves d. recursive arrays 🚧🚧🚧

a. partitions

The quick sort algorithm uses a ________ to divide the array into two pieces. a. pivot b. mid-point c. divider d. none of the above

a. pivot

The class Arrays in the package java.util has several static methods to sort arrays of primitive types into ascending order. Which sort is used? a. quick sort b. merge sort c. shell sort d. insertion sort

a. quick sort

Which sorting algorithm divides the array into two pieces based on the selection of a pivot element? a. quick sort b. merge sort c. radix sort d. selection sort

a. quick sort

Which sort does not use comparisons? a. radix sort b. quick sort c. merge sort d. shell sort

a. radix sort

The radix sort a. restricts the data that it sorts on b. is not suitable as a general-purpose sorting algorithm c. treats array entries as if they were strings that have the same length d. all of the above 🚧🚧🚧

a. restricts the data that it sorts on

The class Arrays in the package java.util has several static methods to sort arrays of Objects into ascending order. Which sort is used? a. merge sort b. quick sort c. shell sort d. insertion sort 🚧🚧🚧 or could be merge sort?

b. quick sort

Why don't we select the median element of all the n-entries in the array to be our pivot point?

It will needrsorting the array & getting the value in the middle. The main goal is to sorting the array, If we select the element we have a chance to end up with circular logic

Which sorting method divides an array into halves, sorts them and merges them back into one sorted array? a. merge sort b. quick sort c. radix sort d. insertion sort

a. merge sort

In quick sort, the partition step takes at most ______ comparisons for n items. a. n b. 1 c. 2n d. n2 🚧🚧🚧

a. n

In merge sort, the merge steps are O(n) when the data a. regardless of the initial order of the array b. is initially close to being sorted c. is initially close to being reverse sorted d. none of the above 🚧🚧🚧: answer might be wrong

a. regardless of the initial order of the array

A sorting algorithm that does not change the relative order of objects that are equal is called a. stable b. relative c. ordered d. all of the above

a. stable

The most programming intensive part of merge sort is a. the merge step b. the division step c. the comparison of items d. none of the above

a. the merge step

The ideal situation in quick sort is when the pivot moves a. to the center of the array b. to the beginning of the array c. to the end of the array d. to a random place in the array

a. to the center of the array

When quick sort partitions arrays as small as 10 entries, the best strategy is to a. use insertion sort on the small array b. use merge sort on the small array c. use shell sort on the small array d. use quick sort down to arrays as small as two entries 🚧🚧🚧 might be "d" also?

a. use insertion sort on the small array

In quick sort, the majority of the work occurs a. before the recursive calls b. in creating the partition c. both a & b d. none of the above 🚧🚧🚧 partition function? before recursive too?

c. both a & b

Which statements are true about the pivot element in quick sort? a. Entries in positions before the pivot are less than or equal to the pivot. b. Entries in positions after the pivot are greater than or equal to the pivot. c. The pivot is in the position that it will occupy in the final sorted array. d. All of the above.

d. All of the above.

Given the following array of 9 elements, trace one iteration of the quick sort algorithm. Use the middle value in the array as the pivot. Assume the array is to be sorted in ascending order. 81 16 4 6 34 11 23 67 52 🚧🚧🚧

run: 81 16 4 6 34 11 23 67 52 23 16 4 6 11 34 81 67 52 BUILD SUCCESSFUL...

Given the following array of 8 elements, show the steps to sort the elements in ascending order using radix sort. 81 16 4 6 34 11 23 67 Ignore these: 81 546 677 9 97 12 53 22

81 16 4 6 34 11 23 67 16 81 4 6 34 11 23 67 4 6 16 81 34 11 23 67 4 6 16 81 11 34 23 67 4 6 16 81 11 23 34 67

Divide and conquer algorithms can only be written recursively.

False

Merge sort is only efficient for sorting a small number of items if you only need to sort a large array once.

False

Radix sort is a general-purpose sorting algorithm. 🚧🚧🚧

False

The iterative merge sort algorithm is much simpler than the recursive algorithm

False

The quick sort algorithm always divides an array in half.

False

Given the following array of 8 elements, trace the merge sort algorithm. Assume the array is to be sorted in ascending order. 81 16 4 6 34 11 23 67 🚧🚧🚧

Tracing Algorithm 81, 16, 4, 6, 34, 11, 23, 67 16, 81, 4, 6, 34, 11, 23, 67 4, 6, 16, 81, 34, 11, 23, 67 4, 6, 16, 81, 11, 34, 23, 67 4, 6, 16, 81, 11, 23, 34, 67 4, 6, 11, 16, 23, 34, 67, 81

A disadvantage of merge sort is the need for a temporary array during the merge step.

True

Divide and conquer algorithms typically use two or more recursive calls.

True

In quick sort, the choice of pivots affects its behavior.

True

In quick sort, the partition places the pivot in the position that it will occupy in the final sorted array.

True

Merging two arrays requires an additional array.

True

The merge sorts in the Java Class Library are stable.

True

Which of the following statements are true about quick sort? a. In practice, it can be faster than merge sort. b. It does not require additional memory that merge sort does. c. It can degrade into an O(n2) sort if the pivot-selection scheme is bad. d. All of the above.

a. In practice, it can be faster than merge sort.

The best-case performance of radix sort on restricted data is a. O(n) b. O(log n) c. O(n log n) d. O(n2) 🚧🚧🚧

a. O(n)

The performance of the merge operation for n items in merge sort is a. O(n) b. O(n2) c. O(n log n) d. O(log n)

a. O(n)

The worst-case performance of radix sort on restricted data is a. O(n) b. O(log n) c. O(n log n) d. O(n2)

a. O(n)

The worst-case performance of quick sort for n items is a. O(n^2) b. O(n log n) c. O(n) d. O(log n)

a. O(n^2)

In the quick sort algorithm, using the median-of-three pivot selection scheme a. avoids worst-case performance for arrays that are already sorted b. avoids worst-case performance for arrays that are nearly sorted c. does not avoid worst-case for randomly distributed arrays d. all of the above

a. avoids worst-case performance for arrays that are already sorted

After merging two arrays is complete, you need to a. copy the merged array back to the original array b. copy the original array to the temporary array c. copy the rest of the first array elements to the temporary array d. copy the rest of the second array elements to the temporary array

a. copy the merged array back to the original array

Radix sort a. distributes digits into buckets b. partitions the array c. merges the array back into place d. all of the above 🚧🚧🚧

a. distributes digits into buckets

Dividing a problem into two or more smaller, distinct problems, then solving them and combining them into a final solution is called a. divide and conquer b. divide and combine c. recursion d. sorting

a. divide and conquer

The worst case situation for quick sort is when a. each partition has one empty subarray b. each partition is of equal size c. the pivot element cannot be determined d. the array elements are initially completely random 🚧🚧🚧🚧

a. each partition has one empty subarray

In merge sort, allocating and initializing an array many times during the recursive calls to merge a. is a waste of time and space b. is the only way to ensure the algorithm will work correctly c. is the only way the merge process will work d. all of the above

a. is a waste of time and space

In quick sort, having every partition form sub arrays of roughly the same size a. is optimal b. creates more work because of repeated comparisons c. slows the processing down d. all of the above

a. is optimal

In quick sort which element would be selected to be the pivot of the following array if the pivot strategy is to use the median of three elements, the first, middle and last. 81 16 4 6 34 11 23 67 52 🚧🚧🚧

the pivot of the given array using the strategy of median of first ,middle and last elements is 52


Ensembles d'études connexes

Life Ch. 6 Underwriting & Policy Issue

View Set

Paradigm- Symbolic Interactionalism

View Set

Chapter 1 What is Heath Psychology?

View Set

A&P 2 Exam 1 discussion questions

View Set

MG62 Exam 3 (chapters 6, 7, 8, & 9)

View Set