Questions Chapter 3 Flashcards

1
Q

Computer sorting algorithms are more limited than humans in that:

a. humans are better at inventing new algorithms.
b. computers can handle only a fixed amount of data
c. humans know what to sort, whereas computers need to be told
d. computers can compare only two things at a time

A

d. computers can compare only two things at a time

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

The two basic operations in simple sorting are _________ items and ________ them (or sometimes ________ them).

A

comparing items, moving them ( or sometimes swapping them)

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

True or False: the bubble sort always ends up comparing every item with every other item

A

False

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

The bubble sort algorithm alternates between:

a. comparing and swapping
b. moving and copying
c. moving and comparing
d. copying and comparing

A

a. comparing and swapping

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

True or False: If there are N items, the bubble sort makes exactly N*N comparisons

A

False

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

In the selection sort:

a. the largest keys accumulate on the left (low indices)
b. a minimum key is repeatedly discovered
c. a number of items must be shifted to insert each item in its correctly sorted position
d. the sorted items accumulate on the right.

A

b. a minimum key is repeatedly discovered

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

True or False: If, in a particular sorting situation, swaps take much longer than comparisons, the selection sort is about twice as fast as the bubble sort

A

True

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

A copy is _____ times as fast as a swap

A

3

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

What is the invariant in the selection sort?

A

Data items with indices less than or equal to out.

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

In the insertion sort, the “marked player” described in the text corresponds to which variable in the insertSort.java program?

a. in
b. out
c. temp
d. a[out]

A

c. temp

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

In the insertion sort, “partially sorted” means that:

a. some items are already sorted, but they may need to be moved.
b. most items are in their final sorted positions, but a few still need to be sorted.
c. only some of the items are sorted
d. group items are sorted among themselves, but items outside the group may need to be inserted in it.

A

d. group items are sorted among themselves, but items outside the group may need to be inserted in it.

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

Shifting a group of items left or right requires repeated _________.

A

copies

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

In the insertion sort, after an item is inserted in the partially sorted group, ti will:

a. never be moved again
b. never be shifted to the left
c. often be moved out of this group
d. find that its group is steadily shrinking

A

b. never be shifted to the left

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

The invariant in the insertion sort is that _______________________________.

A

data items with smaller indices than outer.

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

Stability might refer to:

a. items with secondary keys being excluded from a sort
b. keeping cities sorted by increasing population within each state, in a sort by state
c. keeping the same first names matched with the same last names
d. items keeping the same order of primary keys without regard to secondary keys

A

b. keeping cities sorted by increasing population within each state, in a sort by state.

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

Bubble sort, selection sort, and insertion sort execute in _______ time.

A

O(N^2)

17
Q

A(n) _________ is a condition that remains unchanged while an algorithm runs.

A

invariant

18
Q

The ___________ sort is the least efficient, but the simplest sort.

A

bubble

19
Q

The ___________ sort is the most commonly used of bubble, selection, and insertion sorts.

A

insertion sort

20
Q

A sort is ______ if the order of elements with the same key is retained.

A

stable