Chapter 16 Flashcards

1
Q

True or false:
All of the values in a list have the same type.

A

True

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

True or false:
The size of a list is fixed and cannot be increased or decreased.

A

False

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

True or false:
The sequential search algorithm does not assume that the list is sorted.

A

True

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

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.

A

False

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

True or false:
The bubble sort makes fewer item assignments than comparisons.

A

True

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

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.

A

True

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

True or false:
The insertion sort algorithm sorts the list by moving each element into its proper place.

A

True

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

True or false:
During the sorting phase of insertion sort, the array containing the list is divided into two sublists, sorted and unsorted.

A

True

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

True or false:
Assume that n = 1000. To sort the list, insertion sort makes about 250,000 item assignments.

A

True

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

True or false:
A sequential search is much faster than a binary search.

A

False

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

The sequential search algorithm uses a(n) _______ variable to track whether the item is found.

A

bool

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

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

A

900

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

In a sequential search, if a search item is not in a list of 1000 elements, then ______ key comparisons will be made.

A

1000

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

For sorting a list of length n, a bubble sort uses ______ iterations.

A

n - 1

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

In a bubble sort for list of length n, the first step is to compare elements ________.

A

list[0] and list[n - 1]

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

After the second iteration of a bubble sort for a list of length n, the last _______ are sorted.

A

two elements

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

In the bubble sort algorithm, which code accomplishes swapping values in elements at positions index and index + 1?

A

temp = list[index];
list[index] = list[index + 1];
list[index + 1] = temp;

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

For a list of length n, the bubble sort makes exactly _____ key comparisons

A

n(n - 1) / 2

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

Assume that n = 1000. To sort the list, a bubble sort makes about ____ item comparisons.

A

250,000

20
Q

When moving array values for insertion sort, to move list[4] into list[2], first ______.

A

copy list[4] into temp

21
Q

In the insertion sort function, the variable firstOutOfOrder is initialized to _______, assuming n is the length of the list.

A

1

22
Q

For a list of length n, insertion sort makes _____ item assignments.

A

n(n - 1) /4

23
Q

Sequential search typically searches _______.

A

one half of the list

24
Q

Consider the following list:
int list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95}
When performing a binary search, the element to be found is first compared with _______.

A

39

25
Q

nt list[] = {4, 8, 19, 25, 34, 39, 45, 48, 66, 75, 89, 95}
When performing a binary search for75, after the first comparison, the search is restricted to _______.

A

list[6] … list[11]

26
Q

The formula to find the index of the middle element of a list is ______.

A

(first + last) / 2

27
Q

With the binary search algorithm, _______ key comparison(s) is/are made in the successful case - the last time through the loop.

A

one

28
Q

The statement _____ creates the vector object vecList of size size.

A

vector<elemType> vecList(size);</elemType>

29
Q

A variable declared using the vector type is called a ________.

A

vector container

30
Q

The statement _____ returns the element at the positon index in the vector vecList.

A

vecList[index]

31
Q

Which statement declares intList to be an empty vector?

A

vector<int> intList;</int>

32
Q

Which statement declares intList to be a vector of size 5 and the element to be of type int?

A

vector<int> intList(5);</int>

33
Q

The code below represents the _____ search algorithm.
int unknownSearch(const int list[], int listLength, int searchItem){
int loc;
bool found = false;
loc = 0;
while(loc < listLength && !found)
if(list[loc] == searchItem)
found = true;
else
loc++;
if(found)
return loc;
else
return - 1;
}

A

sequential

34
Q

For a list size of 1000, on average, the sequential search makes about ________ key comparisons.

A

500

35
Q

A(n) _________ search uses the “divide and conquer” technique to search the list.

A

binary

36
Q

In order to apply a(n) _________ search, the list must be sorted.

A

binary

37
Q

The type vector provides the function ________, which returns the first element in the vector object.

A

front()

38
Q

The type vector provides the function ___________, which deletes all elements from the object.

A

clear()

39
Q

The type vector provides the expression _________, which returns the last element of the object.

A

back()

40
Q

The type vector provides the expression _________, which inserts a copy of elem into vecList at the end.

A

push_back(elem)

41
Q

The type vector provides the expression _________, which deletes the last element of vecList.

A

pop_back()

42
Q

The type vector provides the expression _________, which returns true if the object vecList is empty and false otherwise.

A

empty()

43
Q

The type vector provides the expression _________, which returns the maximum number of elements that can be inserted into the object vecList.

A

max_size()

44
Q

If you initially declare a vector object and do not specify its size, then in order to add elements to the vector object, we use the function ________.

A

push_back(elem)

45
Q

The first element in a vector object is at location ____.

A

0

46
Q

If you want to use the class vector in your program you must include the following statement:

A

include <vector></vector>