1/64
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
The linear search is also called a
Sequential search
If a linear search function is searching for a value that is stored in the last element of an 8,000-element array, how many elements will the search code have to read to locate the value?
8,000
In an average case involving an array of N elements, how many times will a linear search function have to read the array to locate a specific value?
N/2
A binary search function is searching for a value that is stored in the middle element of an array. How many times will the function read an element in the array before finding the value?
1
What is the maximum number of comparisons that a binary search function will make when searching for a value in a 2,000-element array?
11
Why is the bubble sort inefficient for large arrays
because items only move by one element at a time
Why is the selection sort more efficient than the bubble sort on large arrays?
because it moves some items immediately to their final position
The _________ search algorithm steps sequentially through an array, comparing each item with the search value.
Linear
The _________ search algorithm repeatedly divides the portion of an array being searched in half.
Binary
The _________ search algorithm is adequate for small arrays but not large arrays.
Linear
If the item being searched for is not in the array, the ________ search algorithm will search to the end of the array.
Linear
The _________ search algorithm requires that the array’s contents be sorted.
Binary
If an array is sorted in _________ order, the values are stored from lowest to highest.
Ascending
If an array is sorted in _________ order, the values are stored from highest to lowest.
Descending
For the numbers below, which statement is true?
10 20 30 55 68 71 85 95 99 120
The numbers are sorted in ascending order.
For the numbers below, which statement is true?
91 86 84 80 75 65 60 53 55 34
The numbers are not sorted in any particular order.
For the numbers below, which statement is true?
81 75 71 68 61 57 53 41 35 34 33 22 18
The numbers are sorted in descending order.
Assume that city1 and city2 are string variables and city1 = “Dallas” and city2 = “Houston”. Which statements are true? [check all that apply]
city1 < city2
city1 > city2
city1 >= city2
city1 != city2
city1 <= city2
city1 == city2
city1 < city2
city1 != city2
city1 <= city2
Assume that state1 and state2 are string variables and state1 = “california” and state2 = “Wisconsin”. Which statements are true? [check all that apply]
state1 > state2
state1 != state2
state1 < state2
state1 >= state2
state1 == state2
state1 <= state2
state1 > state2
state1 != state2
state1 >= state2
The maximum number of comparisons performed by the linear search on an array of N elements is
N
Suppose the binary search algorithm is used to find the value 24 in the array shown below.
10, 15, 17, 24, 35, 36, 41, 45, 48, 57, 65, 68, 70, 74 80, 83, 90
What will be the value of the variable last when the binary search algorithm completes?
7
Suppose the binary search algorithm is used to find the value 65 in the array shown below.
10, 15, 17, 24, 35, 36, 41, 45, 48, 57, 65, 68, 70, 74 80, 83, 90
What will be the value of the variable middle when the binary search algorithm completes?
10
Suppose the binary search algorithm is used to find the value 84 in the array shown below.
11, 12, 18, 21, 25, 30 , 38, 40, 46, 51, 58, 61, 65, 76, 84, 99, 99
What will be the value of the variable first when the binary search algorithm completes?
13
Suppose the binary search algorithm is used to find the value 35 in the array shown below.
11, 12, 16, 21, 29, 33, 38, 39, 40, 45, 47, 49, 55, 58, 61, 74, 92, 94
What will be the value of the variable last when the binary search algorithm completes?
6
Suppose the bubble sort algorithm is used to sort the array shown below.
20, 30, 40, 50, 60, 70, 80, 90, 10
How many times will the bubble sort algorithm pass through the array?
9
Suppose the binary search algorithm is used to find the value 51 in the array shown below.
22, 22, 31, 32, 40, 47, 48, 51, 55, 61, 62, 63, 70 ,77, 86, 94, 96
How many array-element comparisons will the binary search algorithm make?
5
How many array-element swaps will the selection sort algorithm make to sort the array shown below?
5 8 1 2 6 9 7 4 3
6
How many array-element swaps will the selection sort algorithm make to sort the array shown below?
20 30 40 50 60 70 80 90 10
8
Which of the following symbols represents the address operator?
&
Which of the following symbols represents the indirection operator?
*
The address operator
returns the memory address of a variable
A pointer variable is
a variable that holds an address
The indirection operator
dereferences a pointer and allows access to the value of the variable the pointer points to
Which of the following represents the definition of a pointer called intptr? [Check all that apply]
int intptr;
int *intPtr;
int *intptr;
int * intptr;
int* intptr;
int *intptr;
int * intptr;
int* intptr;
Assume that number is an int variable and intptr is an int pointer. Which statement correctly assigns the address of number to the intptr pointer? (Assume that number is not an array.)
*intptr = &number;
intptr = *number;
intptr = &number;
intptr = number;
intptr = &number;
Assume that number is an int array and intptr is an int pointer. Which statement correctly assigns the address of the number array to the intptr pointer?
intptr = &number;
*intptr = &number;
intptr = *number;
intptr = number;
intptr = number;
What does the following code segment display?
int x = 25;
int *ptr;
ptr = &x;
cout << *ptr;
________________________________
the value of the variable ptr
the value of the variable x
the value of the product ptr * ptr
the value of the memory address of x
the value of the variable x
What will be the value of x after the following code segment executes?
int x = 80, y = 60;
int *xptr = &x;
int *yptr = &y;
*yptr = 100;
*xptr = 3*(*yptr) - *xptr;
220
Assume that values and ptr are defined as follows:
int values[4] = {15, 88, 75, 99};
int *ptr;
ptr = values;
Which statements will display the starting address of the values array? [Check all that apply]
cout << values;
cout << ptr;
cout << *values;
cout << *ptr;
cout << values;
cout << ptr;
Assume that values and ptr are defined as follows:
int values[4] = {15, 88, 75, 99};
int *ptr;
ptr = values;
Which statements will display the contents of the first element of the values array? [Check all that apply]
cout << *ptr;
cout << ptr;
cout << *values;
cout << values;
cout << *ptr;
cout << *values;
Assume that values and ptr are defined as follows:
int values[4] = {15, 88, 75, 99};
int *ptr;
ptr = values;
Which statements will display the contents of the third element of the values array? [Check all that apply]
cout << *(ptr + 3);
*values + 3;
*ptr + 3;
cout << *(values + 3);
cout << ptr[3];
cout << values[3];
cout << *(ptr + 3);
cout << *(values + 3);
cout << ptr[3];
cout << values[3];
Assume that values and ptr are defined as follows:
int values[4] = {15, 88, 75, 99};
int *ptr;
ptr = values;
Which of the following statements are true? [Check all that apply]
*ptr = values[0];
ptr == values;
*ptr == values;
values[3] == *(ptr + 3);
values[1] == *ptr + 1;
*ptr == *values;
values[2] == ptr[2];
*ptr = values[0];
ptr == values;
values[3] == *(ptr + 3);
*ptr == *values;
values[2] == ptr[2];
Assume that values and ptr are defined as follows:
int values[4] = {15, 88, 75, 99};
int *ptr;
ptr = values;
Which statements will assign 100 to the third element of the values array? [Check all that apply]
values[3] = 100;
*(ptr + 3) = 100;
*ptr + 3 = 100;
*(values + 3) = 100;
*values + 3 = 100;
ptr[3] = 100;
values[3] = 100;
*(ptr + 3) = 100;
*(values + 3) = 100;
ptr[3] = 100;
If numbers is an array, which statement is equivalent to numbers[index] = 125;?
*(numbers + index) = 125;
What will be the resulting value of x after the following code segment executes?
double numbers[4] = {1.5, 2.5, 3.0, 3.5};
double *ptr1, *ptr2, x;
ptr1 = &numbers[0];
ptr2 = &numbers[2];
x = *ptr1 + *ptr2;
5.5
4.5
5.0
4.0
6.0
4.5
Suppose that values is an int array that is initialized with the values {5, 4, 8, 6, 1}, x is an int variable, and ptr is an int pointer. After the for loop below executes, the resulting value of x will be ___________.
x = 0;
for (int index = 0; index <4; index++)
{
ptr = &values[index];
x += *ptr;
}
23
Suppose that item_numbers, quantity, and ptr are defined as follows:
int item_numbers[500], quantity[500];
int *ptr;
Which of the following are legal assignment statements? [Check all that apply]
item_numbers = quantity;
ptr = item_numbers;
quantity = item_numbers;
quantity = ptr;
ptr = quantity;
item_numbers = ptr;
ptr = item_numbers;
ptr = quantity;
Suppose that numbers is an int array initialized with the values {8, 5, 6, 2, 3, 4}, and ptr is an int pointer. Which element of the numbers array will ptr point to after the following code segment executes?
ptr = numbers;
ptr++;
ptr += 3;
ptr -= 1;
2
Suppose that numbers is an int array initialized with the values {15, 45, 2, 9, 22, 8, 16}, and ptr is an int pointer that currently points to numbers. Which numbers array element will ptr point to after the following code segment executes?
int x = 3;
ptr += x;
ptr = ptr – 2 + x;
ptr++;
8
Which of the following is not a valid pointer initialization statement?
int totals[50], *ptr = totals;
int value = 12, *ptr = &value;
int *ptr = sum, sum = 0;
int *ptr = sum, sum = 0;
Assume ptr is a pointer to an int, and holds the address 12000. On a system with 4-byte integers, what address will be in ptr after the statement ptr += 10; executes?
12010
12400
12040
1212040004
Assume pint is a pointer variable. Which of the following statements are valid? [Check all that apply]
pint += 1;
pint *= 4;
pint = pint + x; // assume x is an int
pint /= 2;
pint++;
pint += 1;
pint = pint + x; // assume x is an int
pint++;
Suppose that numbers is an int array initialized with the values {12, 18, 3, 19, 11}, and that ptr is an int pointer that currently points to numbers. What will the following code segment display?
ptr += 3;
cout << ptr – numbers;
3
Suppose that numbers is an int array initialized with the values {12, 18, 3, 19, 11}, and that ptr is an int pointer that currently points to numbers. Which of the following expressions is true? [Check all that apply]
ptr > &ptr[2]
ptr + 4 < ptr + 2
&numbers[2] < &numbers[4]
*ptr > *(ptr + 2)
ptr + 3 > ptr
ptr == &ptr[0]
&numbers[2] < &numbers[4]
*ptr > *(ptr + 2)
ptr + 3 > ptr
ptr == &ptr[0]
Suppose that numbers is an int array initialized with the values {40, 50, 20, 30, 10}, and that ptr is an int pointer that currently points to numbers. What value is assigned to x in the following statement?
int x = *(ptr + 1) - *(ptr + 3)
20
Suppose that numbers is a double array initialized with the values {1.5, 2.8, 1.9, 2.8, 2.8, 1.9}, and that ptr is a double pointer that currently points to numbers. Which array element of the numbers array will ptr point to after the following code segment executes?
while (ptr < &numbers[4])
ptr++;
numbers[5]
numbers[1]
numbers[2]
numbers[4]
numbers[3]
numbers[4]
A pointer can be used as a function parameter. It gives the function access to the original argument, much like a _________ parameter does.
Reference
When we want to pass the address of a const item into a pointer via a function call, the pointer must be defined in the parameter list as
a pointer to a const item
A pointer that is initialized with an address and cannot point to anything else is
a constant pointer
Which statement is false about the following code segment?
int hours = 40;
int * const ptr = &hours;
ptr cannot point to anything except hours
the value stored in hours cannot change
ptr is a constant pointer
the value stored in hours can change
the value stored in hours cannot change
Which statement is true about dynamic memory allocation
it can allocate memory for a single variable while the program is running
all of these
it can allocate memory for an array while the program is running
it uses the new operator to allocate memory
All of these
Which statement uses dynamic memory allocation to allocate memory for a double array whose size equals number_of_students?
double students [number_of_students];
new double[number_of_students] = students;
students = new double[number_of_students];
students = double[number_of_students];
students = new double[number_of_students];
Which of the following statements correctly releases the memory that was created for the dynamic array sales?
delete [] sales;
delete sales;
delete sales[];
delete new sales;
delete [] sales;
A pointer that contains the address 0 is called a(n)
address pointer
null pointer
int pointer
array pointer
null pointer
When a function returns a pointer, the function should not
return a pointer to a local variable in the function
return a pointer to dynamically allocated memory
return a pointer to data that was passed to the function as an argument
return a pointer to a local variable in the function