Chapter 9 Flashcards
Searching, Sorting, & Algorithm Analysis
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)
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)
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)
True/False: Using a linear search, you are more likely to find an item than if you use a binary search.
False
A binary search begins by examining the ________ element of an array.
A) First
B) Last
C) Largest
D) Middle
E) Smallest
(D)
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)
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
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)
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)
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)
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)
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)
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)
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)
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)