A function accepts scores from 0 through 100 inclusive. Which testing strategy is most likely to reveal an error caused by using < instead of <=?
8 Testing, Debugging, and Algorithmic Efficiency Online Quiz Questions
Use this free practice quiz with 20 questions to review 8 Testing, Debugging, and Algorithmic Efficiency, test your knowledge, and prepare for your next test or exam.
Which two outcomes should a robust test for invalid input verify? Select all that apply.
- A
The invalid input is detected.
- B
The program produces an ordinary result anyway.
- C
The program does not silently produce a misleading result.
- D
The test uses only valid inputs.
What technical term names a defect in a program?
Complete each definition. A states what must be true before an algorithm begins. A states what must be true when it finishes.
True or false: Testing can reveal that a program fails, but debugging is the process used to investigate and correct the cause.
- A
True
- B
False
After fixing a defect, why should the team keep a regression test for it?
- A
It replaces all normal test cases.
- B
It measures only memory usage.
- C
It would fail if the same bug returned.
- D
It guarantees that no future bugs are possible.
Which two statements accurately describe reasoning about algorithm correctness? Select all that apply.
- A
A loop invariant remains true before and after each loop iteration.
- B
A few successful examples prove correctness for every permitted input.
- C
Correctness applies only to the most common input category.
- D
Correctness requires the required result for every input satisfying the stated conditions.
What is the two-word term for a property that remains true before and after each loop iteration?
A binary search examines a sorted list by repeatedly halving the remaining search space. What is its typical running-time growth in terms of the list length n?
- A
O(n)
- B
O(log n)
- C
O(n²)
- D
O(1)
The slow duplicate-checking function compares pairs of items using two nested loops. What is its worst-case time complexity?
- A
O(n²)
- B
O(n)
- C
O(log n)
- D
O(1)
True or false: Replacing the nested-loop duplicate check with a set usually improves the time complexity to O(n), but requires O(n) additional memory.
- A
True
- B
False
Consider this function:
Explain why it gives an incorrect result for some valid inputs, identify a minimal revealing test case, and describe a suitable correction. Include how the revealing test should be used after the fix.
Complete the documentation requirement: Binary search requires the input values to be in nondecreasing order.
In the complete problem-solving workflow, what should a programmer do first when approaching a new programming problem?
- A
Clarify the specification.
- B
Choose a faster data structure immediately.
- C
Document the final solution.
- D
Run the full test set before defining expected behavior.
A score is valid from 0 through 100 inclusive. Which test set best applies boundary-value testing?
- A
Only scores from 1 through 99, because endpoint values are unusual
- B
Scores just below, at, and just above both valid boundaries
- C
Only randomly selected scores between 0 and 100
- D
Only invalid scores below 0
True or false: If an algorithm passes several carefully chosen examples, those examples alone prove that the algorithm is correct for every allowed input.
- A
True
- B
False
A function is intended to count positive values, but it uses for i in range(1, len(values)). On input [4, -1, 2], it returns 1 instead of 2. What is the most likely cause of the failure?
- A
Change
count = 0tocount = 1 - B
Change the condition to
values[i] >= 0 - C
Start the loop at index 0 or iterate directly over the values
- D
Return
len(values)after the loop
In a linear search, what is the name of the property that remains true before and after each iteration?
An algorithm uses two nested loops, and each loop may process all n items in a list. What is the usual worst-case running time?
- A
O(n)
- B
O(n2)
- C
O(logn)
- D
O(1)
What asymptotic time complexity describes a direct calculation whose amount of work does not depend on the input size n? Enter the constant-time complexity in the form O(1).