Midterm Flashcards
The bubble sort is an easy way to arrange data into ascending order, but it cannot arrange data into descending order.
False
The number of comparisons made by a binary search is expressed in powers of two.
True
On average, an item is just as likely to be found near the beginning of an array as near the end.
True
A linear search can only be implemented with integer values.
False
Before you can perform a bubble set, the data must be stored in descending order.
False
If you are using the bubble sort algorithm to sort an array in descending order, the smaller values move toward the end.
True
A selection and a binary search can be applied to STL vectors as well as arrays.
True
a method of locating a specific item in a larger collection of data
search algorithm
The advantage of a linear search is its
simplicity
A ____ search is more efficient than a ____ search.
binary
linear
A binary search begins with the ____ element of an array.
middle
The ___ sort usually performs fewer exchanges than the ___ sort.
selection
bubble
Using a linear search to find a value that is stored in the last element of an array that contains 20,000 elements, ____ elements must be compared.
20,000
A(n) ____ search uses a loop to sequentially step through an array.
linear
When an array is sorted from highest to lowest, it is said to be in
descending order
The ___ is adequate for search through small arrays.
linear search
Algorithms used to arrange random data in some order are ____ algorithms.
sorting
Assume you have two integer values, num1 and num2. Which of the following is the correct way to swap the values in these two variables?
int temp = num1;
num2 = num1;
num1 = num2;
int temp = num2;
num2 = num1;
num1 = temp;
num1 = num2;
num2 = num1;
int temp = num1;
num2 = temp;
temp = num2;
num1 = temp;
None of these
int temp = num2;
num2 = num1;
num1 = temp;
Set first to 0
Set last to the last subscript in the array
Set found to false
Set position to -1
While found is not true and first is less than or equal to last
Set middle to the subscript halfway between array(first) and array(last)
If array(middle) equals the desired value
Set found to true
Set position to middle
Else If array(middle) is greater than the desired value
Set last to middle - 1
Else
Set first to middle + 1
End if
End while
Return position
binary search
The binary search algorithm, a maximum of ___ comparisons will be made on an array of 25,000 elements.
15
With pointer variables you can access but not modify data in other variables.
False
An array name is a pointer constant because the address stored in it cannot be changed at runtime.
True
C++ does not perform array bounds checking, making it possible for you to assign a pointer the address of an element out of the boundaries of an array.
True
In C++11 you can use smart pointers to dynamically allocate memory and not worry about deleting the memory when you are finished using it.
True
When you work with a dereferenced pointer, you are actually working with
a variable whose memory has been allocated
a copy of the value pointed to by the pointer variable
the actual value of the variable whose address is stored in the pointer variable.
None of these
the actual value of the variable whose address is stored in the pointer variable
What does the following statement do?
double *num2;
Declares a double variable named num2
Declares and initializes a pointer variable named num2
Initializes a pointer variable named num2
Declares a pointer variable named num2
None of these
Declares a pointer variable named num2
What does the following statement do?
sum += *array++;
This statement is illegal in C++
This statement will cause a compiler error
This statement assigns the dereferenced pointer’s value, then increments the pointer’s address
This statement increments the dereferenced pointer’s value by one, the assigns that value
None of these
This statement assigns the dereferenced pointer’s value, then increments the pointer’s address.
In the following statement, what does int mean?
int *ptr = nullptr;
The variable named *ptr will store an integer value
The variable named *ptr will store an asterisk and an integer value
ptr is a pointer variable and will store the address of an integer value
The variable named *ptr will store the value in nullptr
None of these
ptr is a pointer variable and will stored the address of an integer value.
Assuming ptr is a pointer variable, what will the following statement output?
cout «_space;*ptr;
the string “*ptr”
the value stored in the variable whose address is contained in ptr
the address of the variable whose address is stored in ptr
the address of the variable stored in ptr
None of these
the value stored in the variable whose address is contained in ptr
Which of the following statements is not valid C++ code?
int ptr = &num1;
int ptr = int *num1;
float num1 = &ptr2;
All of these are valid
All of these are invalid
All of these are invalid
Which of the following statements deletes memory that has been dynamically allocated for an array?
delete [] array;
int array = delete memory;
int delete [ ];
new array = delete;
None of these
delete [] array;
Which of the following statements displays the address of the variable numb?
cout «_space;numb;
cout «_space;*numb;
cin «_space;&numb;
cout «_space;&numb;
cout «_space;&numb;