Questions Chapter 7 Flashcards

1
Q

The Shellsort works by:

a. partitioning the array
b. swapping adjacent elements
c. dealing with widely separated elements
d. starting with the normal insertion sort.

A

c. dealing with widely separated elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If an array has 100 elements, then Knuth’s algorithm would start with an interval of _____.

A

40

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

To transform the insertion sort into the Shellsort, which of the following do you NOT do?

a. substitute h for 1
b. insert an algorithm for creating gaps of decreasing width
c. enclose the normal insertion sort in a loop
d. change the direction of the indices in the inner loop

A

d. change the direction of the indices in the inner loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True or False: a good interval sequence for the Shellsort is created by repeatedly dividing the array size in half.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Fill in the big O values: The speed of the Shellsort is more than _______ but less than _______.

A

Shellsort speed more than O(N^2), but less than O(N*logN)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Partitioning is:

a. putting all the elements larger than a certain value on one end of the array
c. dividing an array in half
d. sorting each half of an array separately

A

a. putting all the elements larger than a certain value on one end of the array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When partitioning, each array element is compared to the _________.

A

pivot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In partitioning, if an array element is equal to the pivot:

a. it is passed over
b. it is passed over or not, depending on the other array element
c. it is placed in the pivot position
d. it is swapped

A

d. it is swapped

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True or False: In quicksort, the pivot can be an arbitrary element of the array

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Assuming larger keys on the right, the partition is:

a. the element between the left and right subarrays
b. the key value of the element between the left and right subarrays
c. the left element in the right subarray
d. the key value of the left element in the right subarray

A

c. the left element in the right subarray

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

QuickSort involves partitioning the original array and then ______________________.

A

recursively calling recQuickSort

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

After a partition in a simple version of quickSort, the pivot may be:

a. used to find the median of the array
b. exchanged with an element of the right subarray
c. used as the starting point of the next partition
d. discarded

A

d. discarded

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Median-of-three partitioning is a way of choosing the _________.

A

pivot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In quicksort, for an array of N elements, the partitionIt( ) method will examine each element approximately ________ times

A

n+2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

True or False: you can speed up quicksort if you stop partitioning when the partition size is 5 and finish by using a different sort

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The expression _____________ means sorting every nth element.

A

n-sorting

17
Q

A sequence of numbers, called the _______ ________ or ______ ________, is used to determine the sorting intervals in the Shellsort

A

interval sequence or gap sequence

18
Q

A widely used interval sequence is generated by the recursive expression __________, where the initial value of __ is 1.

A

interval sequence recursive expression: h=3*h+1

initial value of h is 1

19
Q

The _______ is the value that determines into which group an item will go during partitioning. Items _______ than the _____ go in the ______ group; _______ items go in the ______ group.

A

the pivot value.
items smaller than the pivot go in the left group.
items larger go in the right group.

20
Q

In the partitioning algorithm, two array indices, each in its own ________ _______, start at opposite ends of the array and step toward each other, looking for items that need to be _______.

A

each in its own while loop.

items that need to be swapped.

21
Q

Partitioning operates in ______ time, making N plus 1 or 2 comparisons and fewer than N/2 swaps

A

O(N) time

22
Q

Quicksort partitions an array and then calls itself recursively _______ number of times to sort the remaining subarrays.

A

calls itself recursively 2 times

23
Q

During the partition, the _____ is placed out of the way on the _______ side, and is not involved in the partitioning process

A

pivot is placed out of the way on the right side

24
Q

In the simple version of quicksort, performance is only ______ for already sorted (or inversely sorted) data.

A

O(N^2) time

25
Q

In the more advanced version of quicksort, the pivot can be the ______ of the first, last, and centre items in the subarray. This is called the ____________________ partitioning

A

median. median-of-three partitioning.

26
Q

Median-of-three partitioning effectively eliminates the problem of _______ performance for already sorted data.

A

O(N^2) performance for already sorted data

27
Q

Subarrays smaller than the cutoff can be sorted by ___________ sort.

A

insertion sort

28
Q

The _______ sort is about as fast as quicksort, but uses twice as much memory

A

radix sort