Deck 8: Searching and Sorting Arrays

Full screen (f)
exit full mode
Question
The bubble sort is an easy way to arrange data in ascending order but it cannot arrange data in descending order.
Use Space or
up arrow
down arrow
to flip the card.
Question
A __________ search is more efficient than a __________ search.

A) character, string
B) integer, double
C) binary, linear
D) linear, binary
E) None of these
Question
The linear search repeatedly divides the portion of an array being searched in half.
Question
Before you can perform a bubble sort, the data must be stored in descending order.
Question
A selection sort and a binary search can be applied to STL vectors as well as arrays.
Question
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
Question
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
Question
A(n) __________ search uses a loop to sequentially step through an array.

A) binary
B) unary
C) linear
D) relative
E) None of these
Question
The advantage of a linear search is its

A) complexity
B) efficiency
C) simplicity
D) speed
E) None of these
Question
Before you can perform a selection sort, the data must be stored in ascending order.
Question
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
Question
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
Question
If you are using the bubble sort algorithm to sort an array in descending order, the smaller values move toward the end.
Question
On average, an item is just as likely to be found near the beginning of an array as near the end.
Question
A binary search begins with the __________ element of an array.

A) first
B) last
C) largest
D) middle
E) None of these
Question
You are more likely to find an item by using a binary search than by using a linear search.
Question
The number of comparisons made by a binary search is expressed in powers of two.
Question
A linear search can only be implemented with integer values.
Question
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
Question
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
Question
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
Question
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
Question
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
Question
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.
Question
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
Question
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
Question
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
Question
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
Question
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
Question
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
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/30
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 8: Searching and Sorting Arrays
1
The bubble sort is an easy way to arrange data in ascending order but it cannot arrange data in descending order.
False
2
A __________ search is more efficient than a __________ search.

A) character, string
B) integer, double
C) binary, linear
D) linear, binary
E) None of these
C
3
The linear search repeatedly divides the portion of an array being searched in half.
False
4
Before you can perform a bubble sort, the data must be stored in descending order.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
5
A selection sort and a binary search can be applied to STL vectors as well as arrays.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
6
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
9
The advantage of a linear search is its

A) complexity
B) efficiency
C) simplicity
D) speed
E) None of these
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
10
Before you can perform a selection sort, the data must be stored in ascending order.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
11
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
12
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
13
If you are using the bubble sort algorithm to sort an array in descending order, the smaller values move toward the end.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
14
On average, an item is just as likely to be found near the beginning of an array as near the end.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
15
A binary search begins with the __________ element of an array.

A) first
B) last
C) largest
D) middle
E) None of these
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
16
You are more likely to find an item by using a binary search than by using a linear search.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
17
The number of comparisons made by a binary search is expressed in powers of two.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
18
A linear search can only be implemented with integer values.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
19
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
20
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
21
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
22
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
23
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
24
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.
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
25
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
26
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
27
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
28
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
29
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
30
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
Unlock Deck
Unlock for access to all 30 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 30 flashcards in this deck.