Searching And Sorting Arrays Test Bank Chapter 8 - Test Bank | C++ Control Structures 9e by Tony Gaddis. DOCX document preview.

Searching And Sorting Arrays Test Bank Chapter 8

Starting Out with C++ from Control Structures to Objects, 9e (Gaddis)

Chapter 8 Searching and Sorting Arrays

TRUE/FALSE

1. The bubble sort is an easy way to arrange data in ascending order but it cannot arrange data in descending order.

2. The number of comparisons made by a binary search is expressed in powers of two.

3. On average, an item is just as likely to be found near the beginning of an array as near the end.

4. A linear search can only be implemented with integer values.

5. Before you can perform a selection sort, the data must be stored in ascending order.

6. Before you can perform a bubble sort, the data must be stored in descending order.

7. You are more likely to find an item by using a binary search than by using a linear search.

8. If you are using the bubble sort algorithm to sort an array in descending order, the smaller values move toward the end.

9. A selection sort and a binary search can be applied to STL vectors as well as arrays.

10. The linear search repeatedly divides the portion of an array being searched in half.

MULTIPLE CHOICE

1. A __________ algorithm is a method of locating a specific item of information in a larger collection of data.

a.

sort

b.

search

c.

standard

d.

linear

e.

None of these

2. The advantage of a linear search is its

a.

complexity

b.

efficiency

c.

simplicity

d.

speed

e.

None of these

3. A __________ search is more efficient than a __________ search.

a.

character, string

b.

integer, double

c.

binary, linear

d.

linear, binary

e.

None of these

4. A binary search begins with the __________ element of an array.

a.

first

b.

last

c.

largest

d.

middle

e.

None of these

5. The __________ sort usually performs fewer exchanges than the __________ sort.

a.

bubble, selection

b.

binary, linear

c.

selection, bubble

d.

ANSI, ASCII

e.

None of these

6. Array elements must __________ before a binary search can be performed.

a.

summed

b.

set to zero

c.

positive integers

d.

sorted

e.

None of these

7. 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.

a.

20,000

b.

only the first two

c.

only half

d.

2,000

e.

None of these

8. A(n) __________ search uses a loop to sequentially step through an array.

a.

binary

b.

unary

c.

linear

d.

relative

e.

None of these

9. Data that is to be sorted in ascending order is ordered

a.

from lowest value to highest value

b.

from highest value to lowest value

c.

with a binary search algorithm

d.

by identifying the middle value and going up and down from there

e.

None of these

10. Regardless of the algorithm being used, a search through an array is always performed

a.

from lowest to highest element

b.

from highest to lowest element

c.

beginning with the middle element

d.

using a binary search algorithm

e.

None of these

11. When an array is sorted from highest to lowest, it is said to be in

a.

reverse order

b.

forward order

c.

ascending order

d.

descending order

e.

None of these

12. The __________ is adequate for searching through small arrays.

a.

binary search

b.

the linear search

c.

unary search

d.

bubble sort

e.

None of these

13. Algorithms used to arrange random data in some order are __________ algorithms.

a.

standard search

b.

sorting

c.

linear

d.

binary search

e.

None of these

14. Assume you have two integer variables, num1 and num2. Which of the following is the correct way to swap the values in these two variables?

a.

int temp = num1;

num2 = num1;

num1 = num2;

b.

int temp = num2;

num2 = num1;

num1 = temp;

c.

num1 = num2;

num2 = num1;

d.

int temp = num1;

num2 = temp;

temp = num2;

num1 = temp;

e.

None of these

15. The following function should swap the values contained in two integer variables, num1 and num2. What, if anything, is wrong with this function?

void swap(int num1, int num2)

{

int temp = num2;

num2 = num1;

num1 = temp;

}

a.

You must first initalize temp to 0 before using it.

b.

The variable temp should first be set to num1, not num2.

c.

The swap function must use reference parameters.

d.

The last line should be temp = num1.

e.

Nothing is wrong with this function.

16. The following is the pseudocode for which type of algorithm?

Set found to false

Set position to -1

Set index to 0

While found is false and index < number of elements

If list[index] is equal to search value

found = true

position = index

End If

Add 1 to index

End While

Return position

a.

linear sort

b.

linear search

c.

binary search

d.

selection sort

e.

None of these

17. The following is the pseudocode for which type of algorithm?

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

a.

linear sort

b.

linear search

c.

binary search

d.

selection sort

e.

None of these

18. The following is the pseudocode for which type of algorithm?

For maxElement = each subscript in the array, from the last to the first

For index = 0 To maxElement - 1

If array[index] > array[index + 1]

swap array[index] with array[index + 1]

End If

End For

End For

a.

bubble sort

b.

binary sort

c.

bubble search

d.

selection sort

e.

None of these

19. The following is the pseudocode for which type of algorithm?

For start = each array subscript, from the first to the next-to-last

minIndex = start

minValue = array[start]

For index = start + 1 To size - 1

If array[index] < minValue

minValue = array[index]

minIndex = index

End If

End For

swap array[minIndex] with array[start]

End For

a.

bubble sort

b.

binary sort

c.

bubble search

d.

selection sort

e.

None of these

20. What is the output after the following code executes?

int numerator = 5;

int denominator = 25;

int temp = 0;

temp = numerator;

numerator = denominator;

denominator = temp;

cout << numerator << "/" << denominator << " = " <<

(numerator/denominator) << endl;

a.

5/25 = numerator/denominator

b.

5/25 = 0

c.

5/25 = 0.2

d.

25/5 = 5

e.

25/5 = 25/5

Document Information

Document Type:
DOCX
Chapter Number:
8
Created Date:
Aug 21, 2025
Chapter Name:
Chapter 8 Searching And Sorting Arrays
Author:
Tony Gaddis

Connected Book

Test Bank | C++ Control Structures 9e

By Tony Gaddis

Test Bank General
View Product →

$24.99

100% satisfaction guarantee

Buy Full Test Bank

Benefits

Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party