Questions Chapter 3 Flashcards
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
d. computers can compare only two things at a time
The two basic operations in simple sorting are _________ items and ________ them (or sometimes ________ them).
comparing items, moving them ( or sometimes swapping them)
True or False: the bubble sort always ends up comparing every item with every other item
False
The bubble sort algorithm alternates between:
a. comparing and swapping
b. moving and copying
c. moving and comparing
d. copying and comparing
a. comparing and swapping
True or False: If there are N items, the bubble sort makes exactly N*N comparisons
False
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.
b. a minimum key is repeatedly discovered
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
True
A copy is _____ times as fast as a swap
3
What is the invariant in the selection sort?
Data items with indices less than or equal to out.
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]
c. temp
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.
d. group items are sorted among themselves, but items outside the group may need to be inserted in it.
Shifting a group of items left or right requires repeated _________.
copies
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
b. never be shifted to the left
The invariant in the insertion sort is that _______________________________.
data items with smaller indices than outer.
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
b. keeping cities sorted by increasing population within each state, in a sort by state.