In the temperature_counts function, which category should contain a temperature value of 32?
10. Integrated Problem-Solving Practice Online Quiz Questions
Use this free practice quiz with 20 questions to review 10. Integrated Problem-Solving Practice, test your knowledge, and prepare for your next test or exam.
According to summarize_scores, what does summarize_scores([6, 10, 14]) return?
- A
(3, 20, 10)
- B
(2, 30, 15)
- C
(3, 30, 10)
- D
(3, 30, 30)
Which precondition is necessary for the binary-search implementation in the material to be correct?
- A
The values must be sorted according to the comparison ordering.
- B
The list must contain only distinct values.
- C
The list must contain at least one element.
- D
The target must be larger than the first value.
Which two design decisions match the frequencies function described in the material? Select all correct choices.
- A
Use a mapping from each item to its count.
- B
Require the input list to be sorted first.
- C
Return an empty mapping when the input is empty.
- D
Maintain two parallel lists for items and counts.
Which two statements correctly describe the binary-search implementation in the material? Select all correct choices.
- A
Its worst-case time is O(n).
- B
Its worst-case time is O(log n).
- C
Its extra space is O(1).
- D
It requires an additional set containing every input value.
True or false: In an algorithm, an invariant is a statement that remains true at a specified point during execution.
- A
True
- B
False
True or false: If an algorithm is decidable, it must also be efficient for typical inputs.
- A
True
- B
False
What single-word growth descriptor describes the worst-case running time of the linear_search function?
The sorted list is [1, 2, 2, 2, 5]. What integer index should first_occurrence(values, 2) return? Enter the zero-based index only.
Complete the corrected average function's return expression: return total / .
Complete the loop body so find_first_even progresses when the current value is odd: if values[index] % 2 == 0: return values[index] followed by .
Explain why has_duplicate_fast is generally more efficient than has_duplicate_slow. Compare their time complexity, extra-space usage, and the trade-off involved.
What does the provided binary_search([], 4) return?
- A
It raises an index error.
- B
It returns -1 without entering the loop.
- C
It returns 0 because the list has no elements.
- D
It enters an infinite loop.
According to the temperature_counts function, how is a temperature of 32 classified?
- A
below freezing
- B
comfortable
- C
hot
- D
invalid input
What does summarize_scores([]) return according to the stated design?
- A
(0, 0, 0)
- B
(0, None, None)
- C
(0, 0, None)
- D
([], 0, None)
Using the averaging rule in summarize_scores, what is the average of the scores [6, 8, 10]?
What one-word descriptor characterizes how the worst-case running time of linear search grows with the input size?
True or false: Binary search is appropriate only when the data is sorted according to the same ordering used by its comparisons.
- A
True
- B
False
Why is has_duplicate_fast generally more efficient than has_duplicate_slow for a large list?
- A
It uses no additional memory and guarantees O(1) time.
- B
It uses O(n) time but always uses less memory than the nested-loop method.
- C
It usually reduces expected running time to O(n) by using additional memory.
- D
It sorts the input first, so its worst-case time is O(log n).
For the sorted list [1, 2, 2, 2, 5], why does first_occurrence([1, 2, 2, 2, 5], 2) return index 1 rather than index 2 or 3?
- A
It returns immediately at the first matching index.
- B
It records the match and continues searching the left half.
- C
It discards the left half and searches only for a later match.
- D
It changes the list so duplicate values are removed.