Chapter 16 Flashcards
True or false:
All of the values in a list have the same type.
True
True or false:
The size of a list is fixed and cannot be increased or decreased.
False
True or false:
The sequential search algorithm does not assume that the list is sorted.
True
True or false:
In a bubble sort, the smaller elements move towards the bottom, and the larger elements move toward the top of the list.
False
True or false:
The bubble sort makes fewer item assignments than comparisons.
True
True or false:
The performance of bubble sort can be improved if we stop the sorting process as soon as we find than, in an iteration, no swapping of elements takes place.
True
True or false:
The insertion sort algorithm sorts the list by moving each element into its proper place.
True
True or false:
During the sorting phase of insertion sort, the array containing the list is divided into two sublists, sorted and unsorted.
True
True or false:
Assume that n = 1000. To sort the list, insertion sort makes about 250,000 item assignments.
True
True or false:
A sequential search is much faster than a binary search.
False
The sequential search algorithm uses a(n) _______ variable to track whether the item is found.
bool
If the search item is the 900th item in the list, the sequential search makes _______ key comparisons to determine whether the search item is on the list
900
In a sequential search, if a search item is not in a list of 1000 elements, then ______ key comparisons will be made.
1000
For sorting a list of length n, a bubble sort uses ______ iterations.
n - 1
In a bubble sort for list of length n, the first step is to compare elements ________.
list[0] and list[n - 1]
After the second iteration of a bubble sort for a list of length n, the last _______ are sorted.
two elements
In the bubble sort algorithm, which code accomplishes swapping values in elements at positions index and index + 1?
temp = list[index];
list[index] = list[index + 1];
list[index + 1] = temp;
For a list of length n, the bubble sort makes exactly _____ key comparisons
n(n - 1) / 2