Deck 9: Sorting and Searching Arrays
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/43
Play
Full screen (f)
Deck 9: Sorting and Searching Arrays
1
To order an array of strings in alphabetic order,the sorting algorithm should be structured for ____________ order.
A)alphabetic
B)numeric
C)ascending
D)descending
E)None of the above
A)alphabetic
B)numeric
C)ascending
D)descending
E)None of the above
C
2
Which sorting algorithm sorts the first two elements of an array before inserting the remaining elements into that sorted part of the array?
A)Bubble
B)Selection
C)Insertion
D)Hash
E)None of the above
A)Bubble
B)Selection
C)Insertion
D)Hash
E)None of the above
C
3
As the __________sorting algorithm makes passes through and compares the elements of the array,certain values move toward the end of the array with each pass.
A)Bubble
B)Selection
C)Insertion
D)Hash
E)None of the above
A)Bubble
B)Selection
C)Insertion
D)Hash
E)None of the above
A
4
Which statement is true after the execution of the following statements?
Set x = y
Set y = x
A)x and y contain their original values
B)x and y swapped their values
C)x contains the value in y and y stayed the same
D)y contains the value in x and x stayed the same
E)None of the above
Set x = y
Set y = x
A)x and y contain their original values
B)x and y swapped their values
C)x contains the value in y and y stayed the same
D)y contains the value in x and x stayed the same
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
5
In a binary search,what is the maximum number of comparisons that need to be performed if the array contained 1000 elements?
A)1000
B)500
C)250
D)100
E)None of the above
A)1000
B)500
C)250
D)100
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following sorting algorithms is the least efficient?
A)Bubble sort
B)Insertion sort
C)Selection sort
D)All of the above
E)None of the above
A)Bubble sort
B)Insertion sort
C)Selection sort
D)All of the above
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
7
Swapping the contents of two variables requires a third variable that can serve as a temporary storage location.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
8
What does the variable middle represent in a binary search algorithm?
A)Subscript of the midpoint
B)Middle value in the array
C)Middle value in the portion to be searched
D)The average of two values
E)None of the above
A)Subscript of the midpoint
B)Middle value in the array
C)Middle value in the portion to be searched
D)The average of two values
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
9
Which search algorithm uses three variables to mark positions within the array as it searches for the searchValue?
A)Sequential
B)Binary
C)Parallel
D)Linear
E)None of the above
A)Sequential
B)Binary
C)Parallel
D)Linear
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
10
In the bubble sort algorithm,the two arguments sent into the swap module are ___________.
A)array[index] and array[index-1]
B)array[index+1] and array[index-1]
C)array[index-1] and array[index+1]
D)array[index-1] and array[index]
E)None of the above
A)array[index] and array[index-1]
B)array[index+1] and array[index-1]
C)array[index-1] and array[index+1]
D)array[index-1] and array[index]
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following search algorithms should be used on large arrays if speed is important?
A)Binary
B)Sequential
C)Bubble
D)Selection
E)Insertion
A)Binary
B)Sequential
C)Bubble
D)Selection
E)Insertion
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
12
Which sorting algorithm moves elements to their final sorted position in the array?
A)Bubble
B)Selection
C)Insertion
D)Hash
E)None of the above
A)Bubble
B)Selection
C)Insertion
D)Hash
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
13
When the elements in an array are stored from lowest to highest,the array is sorted in __________ order.
A)Ascending
B)Descending
C)Numeric
D)Alphabetic
E)None of the above
A)Ascending
B)Descending
C)Numeric
D)Alphabetic
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
14
Which statement is true after the execution of the following statements?
Set t = x
Set x = y
Set y = t
A)x and y contain their original values
B)x and y swapped their values
C)x contains the value in y and y stayed the same
D)y contains the value in x and x stayed the same
E)None of the above
Set t = x
Set x = y
Set y = t
A)x and y contain their original values
B)x and y swapped their values
C)x contains the value in y and y stayed the same
D)y contains the value in x and x stayed the same
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
15
In an insertion sort,what order are the elements in an array placed using the following Boolean expression?
// variable p is used to scan the array
While p > 0 AND array[p-1] > array[p]
A)Ascending
B)Descending
C)Numeric
D)Alphabetic
E)None of the above
// variable p is used to scan the array
While p > 0 AND array[p-1] > array[p]
A)Ascending
B)Descending
C)Numeric
D)Alphabetic
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following is a sorting algorithm?
A)Bubble sort
B)Selection sort
C)Insertion sort
D)All of the above
E)None of the above
A)Bubble sort
B)Selection sort
C)Insertion sort
D)All of the above
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
17
In a selection sort,which variable holds the subscript of the element with the smallest value found in the scanned area of the array?
A)minIndex
B)minValue
C)startScan
D)SIZE
E)None of the above
A)minIndex
B)minValue
C)startScan
D)SIZE
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
18
In the swap module,the third variable is declared as a __________ variable.
A)Global
B)Reference
C)Local
D)Constant
E)None of the above
A)Global
B)Reference
C)Local
D)Constant
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
19
The sequential search algorithm is simple and most efficient to use with a large data array.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
20
Which searching algorithm requires the array to be ordered?
A)Sequential
B)Binary
C)Linear
D)Parallel
E)None of the above
A)Sequential
B)Binary
C)Linear
D)Parallel
E)None of the above
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
21
The swap module is executed with three arguments to correctly swap the elements in an array.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
22
In a binary search,if the search fails to find the item on the first attempt,then there are 999 elements left to search in an array of 1000 elements.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
23
The bubble sort is limited to arranging data only in acceding order.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
24
In a sequential search,each element is compared to the searchValue and the search stops when the value is found or the end of the array is encountered.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
25
In a selection sort,when changing from ascending to descending order,only _____ modifications need to be made to the algorithm.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
26
For an array of n items,the average number of comparisons in a sequential search is _______.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
27
In the bubble sort algorithm,the maxElement variable will hold the _______ of the last element that is to be compared to its immediate neighbor.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
28
When using a module to swap the values in two variables,the arguments must be passed into __________ parameters in the module.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
29
In the bubble sort algorithm,the movement of the sorted values is commonly described as seeming to __________ toward the end of the array.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
30
In a sorting algorithm,the sort order can be changed by changing the ________________ operator.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
31
When values in an array need to be swapped,the array and the size of the array have to be sent to the swap module.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
32
Computer programming languages are only able to perform sort algorithms on numeric arrays.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
33
The data in an array can be sorted in either ascending or descending order.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
34
The advantage of the _________ search is its simplicity.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
35
The _________ search algorithm locates an item in an array by repeatedly dividing the array in half.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
36
In a selection sort algorithm,the variable minValue holds the smallest value found in the scanned area of the array.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
37
For an array of n items,the maximum number of comparisons in a sequential search is ______.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
38
The biggest advantage of the bubble sort algorithm is that values move only by one element at a time toward their final destination in the array.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
39
All sorting algorithms contain a group of statements that swap values in array elements.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
40
If the values in an array are sorted in ___________ order,then they are stored from highest to lowest.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
41
In a selection sort,the minValue is set to element _____ in the first iteration of the outer loop.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
42
In a selection sort,the first step is to move the smallest value in the array to element _______,in order to sort the array in ascending order.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck
43
When placing the elements in an array in descending order,the __________ sort begins by finding and placing the largest value in element 0.
Unlock Deck
Unlock for access to all 43 flashcards in this deck.
Unlock Deck
k this deck