Ch 9

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

If a selection sort is used to arrange the numbers 7 5 3 9 2 6 in ascending order, what order will the data be in after the first pass? A) 2 5 3 9 7 6 B) 5 7 3 9 2 6 C) 5 3 7 2 6 9 D) 2 3 5 6 7 9 E) none of the above

A) 2 5 3 9 7 6

To find a value in an ordered array of 100 items, how many values must binary search examine at most? A) 7 B) 10 C) 50 D) 100 E) 101

A) 7

If the item being searched for is not in the array, binary search stops looking for it and reports that it is not there when A) array index first > array index last. B) Boolean variable found equals false. C) Boolean variable found equals true. D) it finds a value larger than the search key. E) it has examined all the elements in the array.

A) array index first > array index last.

The ________ sort usually performs more exchanges than the ________ sort. A) bubble, selection B) selection, bubble C) binary, linear D) linear, binary E) linear, bubble

A) bubble, selection

A(n) ________ algorithm arranges data into some order. A) sorting B) searching C) ordering D) linear E) binary

A) sorting

If a selection sort is used to arrange the numbers 8 6 4 9 3 7 in ascending order, what order will the data be in after the first pass of the sort is completed? A) 3 4 6 7 8 9 B) 3 6 4 9 8 7 C) 6 4 8 3 7 9 D) 6 8 4 9 3 7 E) None of the above

B) 3 6 4 9 8 7

To find a value in an ordered array of 50 items, how many values must binary search examine at most. A) 1 B) 6 C) 10 D) 25 E) 50

B) 6

If a binary search is used to search for the number 4 in the 11-element array shown here int A[] = {1, 2, 3, 4, 6, 7,I8, 9, 10, 12, 17}; which value will the 4 be compared to first? A) 1 B) 7 C) 8 D) 9 E) 17

B) 7

We can estimate the ________ of an algorithm by counting the number of basic steps it requires to solve a problem. A) number of lines of code B) efficiency C) run time D) code quality E) result

B) efficiency

The ________ search is adequate for searching through small arrays, but not through large ones. A) binary B) linear C) selection D) bubble E) random

B) linear

The ________ sort usually performs fewer exchanges than the ________ sort. A) bubble, selection B) selection, bubble C) binary, linear D) linear, binary E) linear, bubble

B) selection, bubble

To find a value that is in an unordered array of 50 items, how many values must linear search examine on average? A) 1 B) 6 C) 25 D) 50 E) 51

C) 25

If a bubble sort is used to arrange the numbers 7 5 3 9 2 6 in ascending order, what order will the data be in after the first pass? A) 2 5 3 9 7 6 B) 5 7 3 9 2 6 C) 5 3 7 2 6 9 D) 2 3 5 6 7 9 E) none of the above

C) 5 3 7 2 6 9

To find a value that is in an unordered array of 100 items, how many values must linear search examine on average? A) 7 B) 10 C) 50 D) 100 E) 101

C) 50

If a bubble sort is used to arrange the numbers 8 6 4 9 3 7 in ascending order, what order will the data be in after the first pass of the sort is completed? A) 3 4 6 7 8 9 B) 3 6 4 9 8 7 C) 6 4 8 3 7 9 D) 6 8 4 9 3 7 E) None of the above

C) 6 4 8 3 7 9

We can measure the complexity of an algorithm that solves a computational problem by determining the number of ________ for an input of size n. A) output statements it has B) times it loops C) basic steps it requires D) variables it uses E) operations it performs

C) basic steps it requires

A(n) ________ search is more efficient than a(n) ________ search. A) string, double B) integer, double C) binary, linear D) linear, binary E) None of the above. All searches are equally efficient.

C) binary, linear

A ________ search uses a loop to sequentially step through an array. A) binary B) unary C) linear D) relative E) bubble

C) linear

When sorting an array of objects, if the values in the data member being sorted on are out of order for two objects, it is necessary to A) examine a different data member. B) swap these two data values. C) swap the entire two objects. D) swap one-by-one all data members in the two objects. E) stop the sort.

C) swap the entire two objects.

To determine that an item is not in an unordered array of 100 items, how many values must linear search examine on average? A) 7 B) 10 C) 50 D) 100 E) 101

D) 100

To determine that a value is not present in an unordered array of 50 items, how many values must linear search examine on average? A) 1 B) 6 C) 25 D) 50 E) 51

D) 50

A binary search begins by examining the ________ element of an array. A) first B) last C) largest D) middle E) smallest

D) middle

Selection sort requires ________ passes to put n data items in order. A) n B) n / 2 C) n / 2 + 1 D) n - 1 E) n + 1

D) n - 1

The linear search is adequate for searching through ________ arrays, but not through ________ ones. A) int, double B) char, string C) ascending, descending D) small, large E) any regular, vector

D) small, large

A sorting algorithm can be used to arrange a set of ________ in ________ order. A) numeric values, ascending B) numeric values, descending C) strings, ascending D) strings, descending E) All of the above.

E) All of the above.

A search can be performed on an array of A) integers. B) strings. C) objects. D) all of the above, but only if the data is in order. E) all of the above whether the data is in order or not.

E) all of the above whether the data is in order or not.

The advantage of a linear search is that A) it is simple. B) it is efficient. C) it is fast. D) it can be used on unordered data. E) both A and D

E) both A and D

Sorted data can be ordered A) from lowest to highest value. B) from highest to lowest value. C) using a bubble sort algorithm. D) using a selection sort algorithm. E) in all of the above ways.

E) in all of the above ways

True/False: If algorithm A requires 2n + 1 basic operations to process an input of size n, and Algorithm B requires 3n + 2 basic operations to process the same input, algorithm A is considered to be more efficient than Algorithm B.

False

True/False: Using a binary search, you are more likely to find an item than if you use a linear search.

False

True/False: Using a linear search, you are more likely to find an item than if you use a binary search.

False

True/False: When an array is sorted from highest to lowest, it is said to be in ascending order.

False

True/False: When searching for an item in an unordered set of data, binary search can find the item more quickly than linear search.

False

True/False: When sorting an array of objects, if the values in the data member being sorted on are out of order for two objects, those two data values should be swapped.

False

If algorithm A requires 2n + 1 basic operations to process an input of size n, and Algorithm B requires 3n + 2 basic operations to process the same input, algorithms A and B are considered to be equally efficient.

True

True/False: A binary search requires that the elements to be in order.

True

True/False: Any sorting algorithm, such as bubble sort or selection sort, that can be used on data stored in an array can also be used on data stored in a vector.

True

True/False: Bubble sort and selection sort can also be used with STL vectors.

True

True/False: When searching for a particular object in an array of objects, it is necessary to compare the search key to the value in each examined object's key field.

True

True/False: When sorting an array of objects or structures, one must decide which data item to sort on.

True


Kaugnay na mga set ng pag-aaral

Chapter 3 Assignment for Module 12

View Set

11. Quiz 2: Eating the Right Foods

View Set

Human Resource Management - Exam 2

View Set