CSCI 321 - Ch. 3

Ace your homework & exams now with Quizwiz!

For each question, assume radix sort has sorted integers by absolute value to produce the array (-12, 23, -42, 73, -78), and is about to build the negative and non-negative buckets to complete the sort. What integers will be placed into the negative bucket? Type answer as: 15, 42, 98

-12, -42, -78

For each question, assume radix sort has sorted integers by absolute value to produce the array (-12, 23, -42, 73, -78), and is about to build the negative and non-negative buckets to complete the sort. After reversal, what integers are in the negative bucket? Type answer as: 15, 42, 98

-78, -42, -12 *The original list was (-12, -42, -78), so the reversed list of negative integers is (-78, -42, -12). Reversal is needed because the original sorting by absolute value doesn't have the negative bucket's list start with the smallest (most negative) value.

Assume quicksort always chooses a pivot that divides the elements into two equal parts. How many total comparisons are required to sort a list of 1024 elements?

10,240 *log_2 1024 * 1024 = 10 * 1024 = 10240 comparisons. There will be log_2 N partitioning levels, and each level requires N comparisons.

How many times longer will sorting a list of 500 elements take compared to a list of 50 elements?

100 *500^2 / 50^2 = 250000 / 2500 = 100. Selection sort's runtime grows quadratically with the input size. If the input increases in size by X times, the runtime increases X^2 times.

Worst case quicksort runtime. How many partitioning levels are required for a list of 1024 elements?

1023 *In the worst case, for N elements, there will be N - 1 levels.

Merge sort How many recursive partitioning levels are required for a list of 2048 elements?

11

How many times is InsertionSortInterleaved called if ShellSort is called with gap array (10, 2, 1)? 3 12 13 20

13 *10 calls for the gap value of 10, 2 calls for the gap value of 2, and 1 call for the gap value of 1. 10 + 2 + 1 = 13

Trace the merge operation by determining the next value added to mergedNumbers. 14 18 35 17 38 49 leftPos = 0, rightPos = 3

14 *14 is added to mergedNumbers: (14). leftPos is incremented.

Given list (20, 14, 85, 3, 9), what value will be in the 0th element after the first pass over the outer loop (i = 1)?

14 *Each outer loop pass inserts one element into the sorted part starting with the element at index 1. In this case, 14 is inserted at index 0, and 20 is moved to index 1. The sorted part is (14, 20) and the unsorted part is (85, 3, 9).

Trace the merge operation by determining the next value added to mergedNumbers. 14 18 35 17 38 49 leftPos = 1, rightPos = 3

17 *17 is added to mergedNumbers: (14, 17). rightPos is incremented.

Trace the merge operation by determining the next value added to mergedNumbers. 14 18 35 17 38 49 leftPos = 1, rightPos = 4

18 *18 is added to mergedNumbers (14, 17, 18). leftPos is incremented.

Consider the array of integers: 51, 47, 96, 52, 27. When placing integers using the 1's digit, how many integers will be in bucket 7? 0 1 2

2 *47 and 27 will be in bucket 7

What will RadixGetLength(17) evaluate to?

2 *After 2 divisions, digits is set to 2 and the loop completes. Then 2 is returned.

For each question, assume a list with 6 elements. With a gap value of 3, how many items will be in each interleaved list? 1 2 3 6

2 *Making 3 lists from a list with 6 items means that each interleaved list will have 2 items.

For each question, assume a list with 6 elements. If a gap value of 2 is chosen, how many interleaved lists will be sorted? 1 2 3 6

2 *The gap value equals the number of interleaved lists.

Given list (32, 33, 35, 37, 38, 36), when i is 5, how many swaps will be performed in the inner loop?

2 *When i = 5, the sorted part is (32, 33, 35, 37, 38) and the current element is 36. The comparisons are: 36 < 38 is true, so swap. The sorted part is now (32, 33, 35, 37, 36, 38). 36 < 37 is true, so swap. The sorted part is now (32, 33, 35, 36, 37, 38). 36 < 35 is false, so no swap.

Merge sort Determine the index j numbers = (1, 2, 3, 4, 5), i = 0, k = 4

2 *j = (i + k) / 2 = (0 + 4) / 2 = 2 j is the midpoint in the list that divides the list into two halves.

Determine the midpoint value. numbers = (1, 2, 3, 4, 5), lowIndex = 0, highIndex = 4

2 *midpoint = lowIndex + ((highIndex - lowIndex)/2) = 0 + ((4 - 0) / 2)

What will RadixGetMaxLength return when the array is (17, 4, 101)?

3 *101 has the largest length, 3 digits, among all the integers in the array.

Given list (1, 9, 17, 18, 2), how many swaps will occur during the outer loop execution (i = 4)?

3 *2 will be swapped with 18, 17, and 9, after which the element is in the correct position and all elements are sorted.

For each question, assume a list with 6 elements. With a gap value of 3, how many interleaved lists will be sorted? 1 2 3 6

3 *The gap value specifies the number of interleaved lists.

Determine the pivot value numbers = (1, 2, 3, 4, 5), lowIndex = 0, highIndex = 4

3 *midpoint = 0 + (4 - 0)/2 = 2 The midpoint is 2, so the pivot value is the element at numbers[2].

Assume quicksort always chooses a pivot that divides the elements into two equal parts. How many partitioning levels are required for a list of 8 elements?

3 1st: (a, b, c, d) (e, f, g, h) 2nd: (a, b) (c, d) (e, f) (g, h) 3rd: (a) (b) (c) (d) (e) (f) (g) (h)

Merge sort How many recursive partitioning levels are required for a list of 8 elements?

3 1st: (a, b, c, d) (e, f, g, h) 2nd: (a, b) (c, d) (e, f) (g, h) 3rd: (a) (b) (c) (d) (e) (f) (g) (h) For N elements, the number of levels is log_2 N. log_2 8 = 3.

Determine the pivot numbers = (55, 7, 81, 26, 0, 34, 68, 125), lowIndex = 3, highIndex = 7

34

Trace the merge operation by determining the next value added to mergedNumbers. 14 18 35 17 38 49 leftPos = 2, rightPos = 4

35 *35 is added to mergedNumbers (14, 17, 18, 35). leftPos is incremented. 5)

Merge sort Determine the right partition numbers = (34, 78, 14, 23, 8, 35), i = 3, k = 5

35 *Elements from indices 5 to 5 are in the right partition. This partition has 1 element, and is already sorted.

Trace the merge operation by determining the next value added to mergedNumbers. 14 18 35 17 38 49 leftPos = 3, rightPos = 4

38 *Left partition is empty, so remaining elements from right partition are added. 38 is added to mergedNumbers (14, 17, 18, 35, 38). rightPos is incremented.

Worst case quicksort runtime. How many partitioning levels are required for a list of 5 elements?

4 *1st: (a) (b, c, d, e) 2nd: (a) (b) (c, d, e) 3rd: (a) (b) (c) (d, e) 4th: (a) (b) (c) (d) (e)

Using the Big O runtime complexity, how many times longer will sorting a list of 20 elements take compared to sorting a list of 10 elements?

4 *20^2 / 10^2 = 400 / 100 = 4. A list with twice as many elements requires 4 times as many comparison.

How many times longer will sorting a list of 20 elements take compared to sorting a list of 10 elements?

4 *A list with twice as many elements requires 4 times as many comparisons.

For each question, assume a list with 6 elements. If a gap value of 4 is chosen, how many interleaved lists will be sorted? A gap value of 4 cannot be used on an array with 6 elements. 2 3 4

4 *The gap value equals the number of interleaved lists. In this case, 2 of the 4 interleaved lists will have 2 elements each, and the other 2 interleaved lists will have 1 element each.

Merge sort Determine the index j numbers = (34, 78, 14, 23, 8, 35), i = 3, k = 5

4 *j = (3 + 5) / 2 = 8 / 2 = 4. As the recursive partitioning continues, partitions are continuously divided in half

Merge sort Determine the right partition numbers = (1, 2, 3, 4, 5), i = 0, k = 4

4, 5 *Elements at indices from j + 1 to k are in right partition.

In the worst case, assuming each comparison takes 1 µs, how long will insertion sort algorithm take to sort a list of 10 elements?

45 microseconds *(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9) * 1 µs = 45 µs

Trace the merge operation by determining the next value added to mergedNumbers. 14 18 35 17 38 49 leftPos = 3, rightPos = 5

49 *49 is added to mergedNumbers (14, 17, 18, 35, 38, 49). Both partitions are empty. mergedNumbers is copied back to numbers.

Determine the midpoint numbers = (55, 7, 81, 26, 0, 34, 68, 125), lowIndex = 3, highIndex = 7

5

Given list (10, 11, 12, 13, 14, 7), how many comparisons will be made during the final outer loop execution (i = 5)?

5 *7 is the smallest element, and will be compared to and swapped with all other elements before reaching the correct position at index 0.

Given the call InsertionSortInterleaved(values, 4, 1, 4), what is the initial value of the loop variable i? 0 1 4 5

5 *i is initialized to startIndex + gap, which in this case is 1 + 4 = 5.

Assume selection sort's goal is to sort in ascending order. Given list (9, 8, 7, 6, 5), what value will be in the 0th element after the first pass over the outer loop (i = 0)?

5 *Each outer loop iteration moves the smallest element in the unsorted part, in this case 5, to the ith position. In other words, the correct element for the ith position is "selected", hence the algorithm's name.

Assume selection sort's goal is to sort in ascending order. Given list (5, 9, 8, 7, 6) and i = 1, what will be the list after completing the second outer loop iteration? Type answer as: 1, 2, 3

5, 6, 8, 7, 9 *The sorted part is just (5) and the unsorted part is (9, 8, 7, 6). The second outer loop iteration will swap the first element in the unsorted part (9) with the smallest element in the unsorted part (6).

How many elements will the temporary merge list have for merging two partitions with 250 elements each?

500 The temporary list must be large enough to merge all elements from the two partitions.

Given list (22, 25, 27, 29, 35, 39, 28, 21), what is the value of i when the first swap executes?

6 *In the insertion sort algorithm, i is the starting position of the current element in the unsorted part. A swap executes when an element is less than the previous element. The first swap executes when the current element is 28 and the element to the left is 39. At that point in the execution of the algorithm, 28 is at index 6. Therefore, the value of i is 6 when the first swap executes.

Given list (10, 20, 6, 14, 7), what will be the list after completing the second outer loop iteration (i = 2)? Type answer as: 1, 2, 3

6, 10, 20, 14, 7 *6 < 20, so 6 and 20 are swapped. 6 < 10, so 6 and 10 are swapped. The sorted part is now (6, 10, 20), and the unsorted part is (14, 7).

Given list (18, 23, 34, 75, 3), how many total comparisons will insertion sort require?

7 *Iterations 1, 2, and 3 requires 1 comparison each, and iteration 4 requires 4 comparisons.

Merge Sort Algorithm

add later

a collection of integer values that all share a particular digit value

bucket

Any array of integer values can be subdivided into ______ by using the integer values' digits

buckets

Shell sort tends to perform well when choosing gap values in ______ order. A common option is to choose powers of 2 minus 1, in _____ order.

descending

a sorting algorithm that operates on an array of elements that can be compared to each other

element comparison sorting algorithm

The list is sorted into ascending order:(3, 9, 44, 18, 76) true false

false

InsertionSortInterleaved will result in an out of bounds array access if called on an array of size 4, a starting index of 1, and a gap value of 4. true false

false *Although i is initialized to 5, which is outside of the array bounds, the for loop's condition of i < arrSize means the loop body is never entered and the array is not accessed at index 5.

A fast sorting algorithm's worst case runtime complexity must be O(NlogN) or better. True False

false *Fast sorting algorithms are classified based on average case, not worst case, runtime complexity.

Bucket concepts Consider integers X and Y, such that X < Y. X will always be in a lower bucket than Y. True False

false *The buckets depend on what digit is being used to place the integers into buckets. Ex: X=19 and Y=22. X is < Y, but when using the 1's digit, X will be in bucket 9 and Y in bucket 2. On the other hand, if using the 10's digit, then X would be in a lower bucket.

The RadixSort() function shown above also works on an array of floating-point values. True False

false *The given RadixSort() function requires array elements to be integers. Radix sort variants that sort floating-point values exist, but require changes to the code.

a positive integer representing the distance between elements in an interleaved list

gap value

Shell sort uses ______ ______ to determine the number of interleaved lists.

gap values

Insertion Sort The inner loop executes on average N/2 times. So the total number of comparisons is proportional to (N−1)x(N/2), or ______.

O(N^2)

Insertion sort's typical runtime is ______

O(N^2)

Selection Sort If a list has N elements, the outer loop executes N - 1 times. For each of those N - 1 outer loop executions, the inner loop executes an average of N/2 times. So the total number of comparisons is proportional to (N−1)⋅N2, or _______.

O(N^2)

The selection sort algorithm runtime is _____

O(N^2)

a sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly inserts the next value from the unsorted part into the correct location in the sorted part

insertion sort

All values in the low partition are _____ than or equal to the pivot value

less

Merge sort divides the input in half until a list of 1 element is reached, which requires _____ partitioning levels.

log N

The list is sorted into ascending order:(chopsticks, forks, knives, spork) True False

true

The list is sorted into ascending order:(great, greater, greatest) True False

true

The list is sorted into descending order:(20, 15, 10, 5, 0) true false

true

For each question, assume radix sort has sorted integers by absolute value to produce the array (-12, 23, -42, 73, -78), and is about to build the negative and non-negative buckets to complete the sort. What is the final array after RadixSort concatenates the two buckets? Type answer as: 15, 42, 98

-78, -42, -12, 23, 73

Worst case quicksort runtime. Given numbers = (7, 4, 2, 25, 19), lowIndex = 0, and highIndex = 4, what are the contents of the low partition? Type answer as: 1, 2, 3

2 The low partition is (2), and the high partition is (4, 7, 25, 19).

Worst case quicksort runtime. How many total calls to the Quicksort() function are made to sort a list of 1024 elements?

2047 *The initial call counts for 1. After that, N - 1 partitioning levels exist, and each level makes 2 recursive calls. 1+2x(1024−1) = 2047 calls

Given list (25, 74, 92, 77, 90, 12, 97), how many swaps are needed to sort the list?

7 *swap 77 with 92: (25, 74, 77, 92, 90, 12, 97) swap 90 with 92: (25, 74, 77, 90, 92, 12, 97) swap 12 with 92: (25, 74, 77, 90, 12, 92, 97) swap 12 with 90: (25, 74, 77, 12, 90, 92, 97) swap 12 with 77: (25, 74, 12, 77, 90, 92, 97) swap 12 with 74: (25, 12, 74, 77, 90, 92, 97) swap 12 with 25: (12, 25, 74, 77, 90, 92, 97)

Insertion Sort Algorithm

InsertionSort(numbers, numbersSize) { i = 0 j = 0 temp = 0 // Temporary variable for swap for (i = 1; i < numbersSize; ++i) { j = i // Insert numbers[i] into sorted part // stopping once numbers[i] in correct position while (j > 0 && numbers[j] < numbers[j - 1]) { // Swap numbers[j] and numbers[j - 1] temp = numbers[j] numbers[j] = numbers[j - 1] numbers[j - 1] = temp --j } } }

Insertion Sort If a list has N elements, the outer loop executes ____ times. For each outer loop execution, the inner loop may need to examine all elements in the sorted part.

N - 1

Shell sort's time compexity at worst is _______

O(N ^ (3/2))

The merge sort algorithm's runtime is _________

O(N log N)

The quicksort algorithm's runtime is typically ______

O(N log N)

Which fast sorting algorithm's worst case runtime complexity is worse than O(NlogN)? Quicksort Heap sort Radix sort

Quicksort *Quicksort's worst case runtime complexity is O(N^2), which is worse than O(NlogN).

Which list leads to worst-case performance with insertion sort?

The worst case performance for insertion sort is when the list elements are in descending order. Ex: (77, 48, 43, 40, 36, 23). When the elements are in descending order, i swaps occur for each execution of the outer loop

The fastest average runtime complexity of a comparison sorting algorithm is O(NlogN). True False

true

All values in the high partition are ______ than or equal to the pivot value.

greater

Once the pivot is chosen, the quicksort algorithm divides the array into two parts, referred to as the _____ partition and the _____ partition.

low, high

Given numbers = (87, 49, 55, 26, 74, 80, 57), pivot = 74 What is the low partition after the partitioning algorithm is completed? What is the high partition after the partitioning algorithm is completed?

low: 57, 49, 55, 26, 74 high: 80, 87

a sorting algorithm that divides a list into two halves, recursively sorts each half, and then merges the sorted halves to produce a sorted list. The recursive partitioning continues until a list of 1 element is reached, as a list of 1 element is already sorted.

merge sort

Determine if each of the following lists is unsorted, sorted, or nearly sorted. Assume ascending order. (23, 24, 36, 48, 19, 50, 101)

nearly sorted

a list that only contains a few elements not in sorted order

nearly sorted list

Is radix sort a comparison sorting algorithm?

no

To partition the input, quicksort chooses a ______ to divide the data into low and high parts.

pivot

quicksort: The ______ can be any value within the array being sorted, commonly the value of the middle array element. Ex: For the list (4, 34, 10, 25, 1), the middle element is located at index 2 (the middle of indices [0, 4]) and has a value of 10.

pivot

a sorting algorithm that repeatedly partitions the input into low and high parts (each part unsorted), and then recursively sorts each of those parts.

quicksort

Sorting algorithms that ARE fast

quicksort O(NlogN) merge sort O(NlogN) heap sort O(NlogN) radix sort O(N)

a sorting algorithm designed specifically for integers. The algorithm makes use of a concept called buckets and is a type of bucket sort.

radix sort

a sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly selects the proper next value to move from the unsorted part to the end of the sorted part

selection sort

Sorting algorithms that are NOT fast

selection sort O(N^2) insertion sort O(N^2) shell sort O(N^2)

Determine if each of the following lists is unsorted, sorted, or nearly sorted. Assume ascending order. (6, 14, 85, 102, 102, 151)

sorted

Consider the array of integers: 51, 47, 96, 52, 27. When placing integers using the 1's digit, how many integers will be in bucket 5? 0 1 2

0 *No integers have 5 as the 1's digit.

Given the call InsertionSortInterleaved(values, 10, 0, 5), what are the indices of the first two elements compared? 1 and 5 1 and 6 0 and 4 0 and 5

0 and 5 *The code initializes one index to the starting index of 0 and the other index to the starting index of 0 plus the gap value of 5. 0 + 5 = 5.

Merge sort numbers: 28 88 64 12 50 16 79 87 What call sorts the numbers array? MergeSort(numbers, ____, _____)

0, 7 MergeSort()'s second parameter is the index of the partition's first element. MergeSort()'s third parameter is the index of the partition's last element.

Determine the midpoint numbers = (200, 11, 38, 9), lowIndex = 0, highIndex = 3

1

Shell sort begins by picking an arbitrary collection of gap values. For each gap value K, K calls are made to the insertion sort variant function to sort K interleaved lists. Shell sort ends with a final gap value of ____, to finish with the regular insertion sort.

1

Consider the array of integers: 51, 47, 96, 52, 27. When placing integers using the 10's digit, how many will be in bucket 9? 0 1 2

1 *96 will be in bucket 9.

Given list (10, 11, 12, 13, 14, 15), how many comparisons will be made during the third outer loop execution (i = 3)?

1 *Only a single comparison is needed for elements already in sorted order.

When sorting the array (57, 5, 501) with RadixSort, what is the largest number of integers that will be in bucket 5 at any given moment?

1 *When processing the 1's digit, only 5 has a digit value of 5. When processing the 10's digit, only 57 has a digit value of 5. When processing the 100's digit, only 501 has a digit value of 5. Bucket 5 never contains more than one integer.

Determine the pivot numbers = (200, 11, 38, 9), lowIndex = 0, highIndex = 3

1 *midpoint = 0 + (3 - 0)/2 = 1 The midpoint is 1, so the pivot value is the element at numbers[1].

Assume selection sort's goal is to sort in ascending order. Given list (9, 8, 7, 6, 5), how many swaps will occur during the first pass of the outer loop (i = 0)?

1 *One swap occurs during each pass of the outer loop. The swap occurs at the end of the outer loop, once the search for the smallest element (inner loop) has completed.

Merge sort Determine the left partition numbers = (1, 2, 3, 4, 5), i = 0, k = 4

1, 2, 3 *Elements at indices from i to j, inclusive, are in the left partition.

Assume quicksort always chooses a pivot that divides the elements into two equal parts. How many partitioning levels are required for a list of 1024 elements?

10 *log_2 1024 = 10. Assuming equal-size partitions, for N elements, the number of levels is log_2 N.

For each question, assume radix sort has sorted integers by absolute value to produce the array (-12, 23, -42, 73, -78), and is about to build the negative and non-negative buckets to complete the sort. What integers will be placed into the non-negative bucket? Type answer as: 15, 42, 98

23, 73

Merge sort Determine the left partition numbers = (34, 78, 14, 23, 8, 35), i = 3, k = 5

23, 8 *Elements at indices 3 to 4 are in the left partition. This partition will again be divided into two halves. Each of those halves will have one element.

When sorting a list with 50 elements, indexSmallest will be assigned to a minimum of _____ times.

49 *The outer loop always assigns to indexSmallest at the beginning of each iteration. The inner loop never assigns to indexSmallest if the list is already sorted. A list of 50 elements causes 49 outer loop iterations, and thus a minimum of 49 assignments to indexSmallest.

Insertion sort runtime for nearly sorted input

For each outer loop execution, if the element is already in sorted position, only a single comparison is made. Each element not in sorted position requires at most N comparisons. If there are a constant number, C, of unsorted elements, sorting the N - C sorted elements requires one comparison each, and sorting the C unsorted elements requires at most N comparisons each. The runtime for nearly sorted inputs is O((N - C) * 1 + C * N) = O(N).

Interleaved Insertion Sort Algorithm

InsertionSortInterleaved(numbers, numbersSize, startIndex, gap) { i = 0 j = 0 temp = 0 // Temporary variable for swap for (i = startIndex + gap; i < numbersSize; i = i + gap) { j = i while (j - gap >= startIndex && numbers[j] < numbers[j - gap]) { temp = numbers[j] numbers[j] = numbers[j - gap] numbers[j - gap] = temp j = j - gap } } }

For sorted or nearly sorted inputs, insertion sort's runtime is _____

O(N)

Merge sort requires _______ additional memory elements for the temporary array of merged elements.

O(N)

element comparison sorting algorithms

Selection sort, insertion sort, shell sort, quicksort, merge sort, and heap sort

Selection Sort Algorithm

SelectionSort(numbers, numbersSize) { i = 0 j = 0 indexSmallest = 0 temp = 0 // Temporary variable for swap for (i = 0; i < numbersSize - 1; ++i) { // Find index of smallest remaining element indexSmallest = i for (j = i + 1; j < numbersSize; ++j) { if ( numbers[j] < numbers[indexSmallest] ) { indexSmallest = j } } // Swap numbers[i] and numbers[indexSmallest] temp = numbers[i] numbers[i] = numbers[indexSmallest] numbers[indexSmallest] = temp } }

Shell Sort Algorithm

ShellSort(numbers, numbersSize, gapValues) { for each (gapValue in gapValues) { for (i = 0; i < gapValue; i++) { InsertionSortInterleaved(numbers, numbersSize, i, gapValue) } } }

Which list leads to best-case performance with insertion sort?

The best case performance for insertion sort is when the list elements are in ascending order. Ex: (12, 25, 48, 71, 97, 99). When the elements are in ascending order, the while loop condition is never true, so no swaps occur.

Bucket concepts Integers will be placed into buckets based on the 1's digit. More buckets are needed for an array with one thousand integers than for an array with one hundred integers. True False

false *Base-10 integers have 10 possible values (0-9) for a digit, meaning 10 buckets are necessary regardless of array size.

Insertion sort is a fast sorting algorithm. True False

false *Insertion sort has an runtime of O(N^2). A sorting algorithm needs an average runtime of O(NlogN) or better to be considered a fast sorting algorithm.

RadixSort has a space complexity of O(1). True False

false *Radix sort always uses 10 buckets, but the number of integers in the buckets increases as the array gets larger. Because buckets collectively must store the entire array's contents of n elements, the space complexity of RadixSort is O(n).

Calling ShellSort with gap array (7, 3, 1) vs. (3, 7, 1) produces the same result with no difference in efficiency. True False

false *ShellSort will produce a sorted array either way, but the order of gap values can affect efficiency.

If a gap value of 2 is chosen, then the following 2 function calls will fully sort a list: InsertionSortInterleaved(list, 9, 0, 2) InsertionSortInterleaved(list, 9, 1, 2) True False

false *The two InsertionSortInterleaved calls sort two interleaved lists, but do not guarantee the entire list is sorted.

a sorting algorithm that has an average runtime complexity of O(NlogN) or better

fast sorting algorithm

For each interleaved list, if an element is at index i, the next element is at index i + _____ ______

gap value

a sorting algorithm specifically for an array of integers: The algorithm processes one digit at a time starting with the least significant digit and ending with the most significant.

radix sort

a sorting algorithm that treats the input as a collection of interleaved lists, and sorts each list individually with a variant of the insertion sort algorithm

shell sort

the process of converting a list of elements into ascending (or descending) order

sorting

The merge sort algorithm uses ____ index variables to keep track of the elements to sort for each recursive function call. The index variable i is the index of first element in the list, and the index variable k is the index of the last element. The index variable j is used to divide the list into two halves. Elements from i to j are in the left half, and elements from j + 1 to k are in the right half.

three

Merge sort is a fast sorting algorithm. True False

true

Radix sort is a fast sorting algorithm. True False

true

Selection sort may require a large number of comparisons true false

true

Shell sort begins by choosing a gap value K and sorting K interleaved lists in place. Shell sort finishes by performing a standard insertion sort on the entire array. true false

true

Shell sort will correctly sort arrays using any positive integer gap values in any order, provided a gap value of 1 is included. true false

true

The list is sorted into descending order:(99.87, 99.02, 67.93, 44.10) true false

true

The list is sorted into descending order:(F, D, C, B, A) True False

true

The worst case runtime for the quicksort algorithm is O(N^2). Fortunately, this worst case runtime rarely occurs. True False

true

Values equal to the pivot may appear in either or both of the partitions. True False

true

Consider the array of integers: 51, 47, 96, 52, 27. All integers would be in bucket 0 if using the 100's digit. True False

true *Because every integer is less than 100, the 100's digit in each integer is implicitly 0.

ShellSort will properly sort an array using any collection of gap values, provided the collection contains 1. True False

true *Calling InsertionSortInterleaved with a gap of 1 is equivalent to the standard insertion sort.

Bucket concepts All integers from an array could be placed into the same bucket, even if the array has no duplicates. True False

true *Ex: When using the 1's digit for the array (10, 20, 30, 40), each integer will be in bucket 0, even though each integer is distinct.

When sorting an array with n elements, the maximum number of elements that RadixSort may put in a bucket is n. True False

true *If all integers in the array share a digit, then all integers will be put into the same bucket. Ex: If every element in the array were 7, then every element would go into bucket 7.

Selection sort can be used to sort an array of strings. True False

true *Selection sort is a comparison sorting algorithm, and a string can be compared against another string, so selection sort can sort an array of strings.

When sorting an array of n 3-digit integers, RadixSort's worst-case time complexity is O(n). True False

true *With all integers being 3 digits, maxDigits is the constant 3 and RadixSort has a constant number of iterations in the outer loop. Each inner loop is O(n), making the algorithm O(n).

Radix sort _____ steps are needed for each digit: First, all array elements are placed into buckets based on the current digit's value. Then, the array is rebuilt by removing all elements from buckets, in order from lowest bucket to highest.

two

Determine if each of the following lists is unsorted, sorted, or nearly sorted. Assume ascending order. (15, 19, 21, 24, 2, 3, 6, 11)

unsorted


Related study sets

Digital Marketing and Social Media

View Set

Chapter 14: Musculoskeletal Imaging & Superficial Structure (Penny)

View Set

biochem 2 chris part, Biochem 2 Ch 20, Biochem 2 bonus test, Biochem 2 Ch 21

View Set

BCH 419 Alzheimer's Disease & ALS (exam 1)

View Set