Deck 19: Searching, Sorting and Big O
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/22
Play
Full screen (f)
Deck 19: Searching, Sorting and Big O
1
Big O highlights ________ factors and ignores terms that become unimportant with ________ n values.
A) insignificant, low
B) insignificant, high
C) dominant, low
D) dominant, high
A) insignificant, low
B) insignificant, high
C) dominant, low
D) dominant, high
dominant, high
2
Big O notation is concerned with the growth rate of algorithm run times, so ________.
A) constants are dominant
B) constants are ignored
C) constant terms are emphasized
D) constants with large values are more important than those with low values
A) constants are dominant
B) constants are ignored
C) constant terms are emphasized
D) constants with large values are more important than those with low values
constants are ignored
3
Which of the following is not a name for a big O run time?
A) Constant run time.
B) Variable run time.
C) Linear run time.
D) Quadratic run time.
A) Constant run time.
B) Variable run time.
C) Linear run time.
D) Quadratic run time.
B
4
Big O notation describes ________.
A) the amount of memory required by an algorithm.
B) the difficulty of writing an algorithm to solve a specific problem.
C) an algorithm's efficiency in terms of the work required to solve a problem.
D) the length of an algorithm for solving a specific problem.
A) the amount of memory required by an algorithm.
B) the difficulty of writing an algorithm to solve a specific problem.
C) an algorithm's efficiency in terms of the work required to solve a problem.
D) the length of an algorithm for solving a specific problem.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
5
An O(n) algorithm is referred to as having a _______ run time.
A) constant
B) linear
C) quadratic
D) negative
A) constant
B) linear
C) quadratic
D) negative
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
6
What does the first pass of selection sort do?
A) Splits the array into two approximately equal pieces.
B) Orders the first two elements of the array.
C) Partitions the array into two unequal pieces depending on whether each element in the array is greater or less that some pivot element.
D) Locates the smallest element in the array and swaps it into the zeroth position.
A) Splits the array into two approximately equal pieces.
B) Orders the first two elements of the array.
C) Partitions the array into two unequal pieces depending on whether each element in the array is greater or less that some pivot element.
D) Locates the smallest element in the array and swaps it into the zeroth position.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following is a negative of binary search?
A) It requires significantly more memory than linear search.
B) It is slower than linear search.
C) The data must be in sorted order.
D) None of the above.
A) It requires significantly more memory than linear search.
B) It is slower than linear search.
C) The data must be in sorted order.
D) None of the above.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following statements is true?
A) The binary search algorithm is less efficient than the linear search, but it requires that the array be sorted.
B) The binary search algorithm is more efficient than the linear search, but it requires that the array be unsorted.
C) The binary search algorithm is more efficient than the linear search, but it requires that the array be sorted.
D) The binary search algorithm is less efficient than the linear search, but it requires that the array be unsorted.
A) The binary search algorithm is less efficient than the linear search, but it requires that the array be sorted.
B) The binary search algorithm is more efficient than the linear search, but it requires that the array be unsorted.
C) The binary search algorithm is more efficient than the linear search, but it requires that the array be sorted.
D) The binary search algorithm is less efficient than the linear search, but it requires that the array be unsorted.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
9
What is the term used for binary search's run time?
A) Linear run time.
B) Quadratic run time.
C) Constant run time.
D) Logarithmic run time.
A) Linear run time.
B) Quadratic run time.
C) Constant run time.
D) Logarithmic run time.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
10
What is the efficiency of selection sort?
A) O(n2).
B) O(n log n).
C) O(n).
D) O(1).
A) O(n2).
B) O(n log n).
C) O(n).
D) O(1).
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
11
Using a binary search, what is the maximum number of comparisons required to find a search key in a 31-element sorted array?
A) 4.
B) 5.
C) 32.
D) 1.
A) 4.
B) 5.
C) 32.
D) 1.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
12
How much faster is insertion sort with a 15-element array than with a 60-element array?
A) 60 times.
B) 4 times.
C) 15 times.
D) 19 times.
A) 60 times.
B) 4 times.
C) 15 times.
D) 19 times.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
13
is the efficiency of linear search?
A) O(1).
B) O(log n).
C) O(n).
D) O(n2).
A) O(1).
B) O(log n).
C) O(n).
D) O(n2).
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
14
A searching algorithm that's O(1)________.
A) requires one comparison
B) does not necessarily require only one comparison
C) can search only an array of one item.
D) None of the above.
A) requires one comparison
B) does not necessarily require only one comparison
C) can search only an array of one item.
D) None of the above.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following is a way to sort data?
A) Alphabetically.
B) In increasing numerical order.
C) Based on an account number.
D) All of the above.
A) Alphabetically.
B) In increasing numerical order.
C) Based on an account number.
D) All of the above.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
16
What does each iteration of the insertion sort algorithm do?
A) Each iteration takes the next smallest element and inserts it at the beginning of the array.
B) Each iteration takes the next element in the unsorted portion of the array and inserts it into the sorted portion.
C) Sorted subarrays are inserted into the larger array.
D) Each iteration determines the location of a pivot and inserts it into place.
A) Each iteration takes the next smallest element and inserts it at the beginning of the array.
B) Each iteration takes the next element in the unsorted portion of the array and inserts it into the sorted portion.
C) Sorted subarrays are inserted into the larger array.
D) Each iteration determines the location of a pivot and inserts it into place.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
17
Different sorting algorithms on a particular array produce the same result; the choice of algorithm affects ________ of the program that implements the algorithm.
A) only the run time
B) the run time and the memory use
C) only the memory use
D) neither the run time nor the memory use
A) only the run time
B) the run time and the memory use
C) only the memory use
D) neither the run time nor the memory use
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
18
What is the base case for the recursive merge sort algorithm?
A) Any array that is already sorted.
B) A two-element array.
C) A one-element array.
D) A zero-element array.
A) Any array that is already sorted.
B) A two-element array.
C) A one-element array.
D) A zero-element array.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
19
How many comparisons will the linear search algorithm make if the search key is not in an array of 10 elements?
A) 0.
B) 10.
C) 9.
D) 5.
A) 0.
B) 10.
C) 9.
D) 5.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
20
The linear search algorithm runs in ________time.
A) quadratic
B) O(n)
C) constant
D) nonlinear
A) quadratic
B) O(n)
C) constant
D) nonlinear
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following sorting algorithms is the fastest?
A) Selection sort.
B) Insertion sort.
C) Merge sort.
D) They all run at roughly the same speed.
A) Selection sort.
B) Insertion sort.
C) Merge sort.
D) They all run at roughly the same speed.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
22
What is the efficiency of merge sort?
A) O(log n).
B) O(n).
C) O(n log n).
D) O(n2).
A) O(log n).
B) O(n).
C) O(n log n).
D) O(n2).
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck