Deck 9: Searching, Sorting, Algorithm Analysis

Full screen (f)
exit full mode
Question
When searching for an item in an unordered set of data, binary search can find the item more quickly than linear search.
Use Space or
up arrow
down arrow
to flip the card.
Question
A binary search begins by examining the ________ element of an array.

A) first
B) last
C) largest
D) middle
E) smallest
Question
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
Question
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
Question
Using a linear search, you are more likely to find an item than if you use a binary search.
Question
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
Question
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.
Question
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.
Question
The ________ sort usually performs fewer exchanges than the ________ sort.

A) bubble, selection
B) selection, bubble
C) binary, linear
D) linear, binary
E) linear, bubble
Question
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.
Question
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
Question
Bubble sort and selection sort can also be used with STL vectors.
Question
When sorting an array of objects or structures, one must decide which data item to sort on.
Question
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
Question
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.
Question
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
Question
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
Question
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.
Question
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
Question
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.
Question
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.
Question
The ________ sort usually performs more exchanges than the ________ sort.

A) bubble, selection
B) selection, bubble
C) binary, linear
D) linear, binary
E) linear, bubble
Question
A(n) ________ algorithm arranges data into some order.

A) sorting
B) searching
C) ordering
D) linear
E) binary
Question
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
Question
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.
Question
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.
Question
A ________ search uses a loop to sequentially step through an array.

A) binary
B) unary
C) linear
D) relative
E) bubble
Question
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
Question
Using a binary search, you are more likely to find an item than if you use a linear search.
Question
The ________ search is adequate for searching through small arrays, but not through large ones.

A) binary
B) linear
C) selection
D) bubble
E) random
Question
A binary search requires that the elements be in order.
Question
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, 8, 9, 10, 12, 17};
Which value will the 4 be compared to first?

A) 1
B) 7
C) 8
D) 9
E) 17
Question
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
Question
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
Question
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.
Question
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
Question
When an array is sorted from highest to lowest, it is said to be in ascending order.
Question
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
Question
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
Question
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.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 9: Searching, Sorting, Algorithm Analysis
1
When searching for an item in an unordered set of data, binary search can find the item more quickly than linear search.
False
2
A binary search begins by examining the ________ element of an array.

A) first
B) last
C) largest
D) middle
E) smallest
D
3
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
4
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
Using a linear search, you are more likely to find an item than if you use a binary search.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
The ________ sort usually performs fewer exchanges than the ________ sort.

A) bubble, selection
B) selection, bubble
C) binary, linear
D) linear, binary
E) linear, bubble
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
Bubble sort and selection sort can also be used with STL vectors.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
When sorting an array of objects or structures, one must decide which data item to sort on.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
The ________ sort usually performs more exchanges than the ________ sort.

A) bubble, selection
B) selection, bubble
C) binary, linear
D) linear, binary
E) linear, bubble
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
A(n) ________ algorithm arranges data into some order.

A) sorting
B) searching
C) ordering
D) linear
E) binary
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
A ________ search uses a loop to sequentially step through an array.

A) binary
B) unary
C) linear
D) relative
E) bubble
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
Using a binary search, you are more likely to find an item than if you use a linear search.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
The ________ search is adequate for searching through small arrays, but not through large ones.

A) binary
B) linear
C) selection
D) bubble
E) random
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
A binary search requires that the elements be in order.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
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, 8, 9, 10, 12, 17};
Which value will the 4 be compared to first?

A) 1
B) 7
C) 8
D) 9
E) 17
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
When an array is sorted from highest to lowest, it is said to be in ascending order.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
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.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 40 flashcards in this deck.