Which debugging approach loads the program with print statements to display…
2021
Which debugging approach loads the program with print statements to display the intermediate values, in the hope that some of the printed values will help identify the statement that is in error?
- A.
Backtracking
- B.
Cause Elimination Method
- C.
Brute Force Method
- D.
Program Slicing
Attempted by 45 students.
Show answer & explanation
Correct answer: C
Debugging strategies are classified by the mechanism they use to narrow down a fault. The four classical strategies (Pressman's classification) are: the Brute Force method, which inserts print statements, memory dumps, or execution traces throughout the program to display run-time/intermediate values and scans them for a clue; Backtracking, which starts at the point where the error symptom was observed and manually traces the source code backward until the error's origin is found; the Cause Elimination method, which lists the plausible causes of a symptom and designs tests to eliminate them one by one (induction/deduction); and Program Slicing, which restricts the search to only the set of statements that could have affected a specific variable's value at a given point (a "slice" of the program).
This question describes inserting print statements to display intermediate values in the hope that one of the printed values exposes the faulty statement -- that is exactly the Brute Force method: it is the most commonly used but least systematic strategy, typically reached for when no other clue is available.
Backtracking works by manually retracing the code backward from the point the symptom was noticed -- it does not rely on inserting print statements to display intermediate values.
The Cause Elimination method lists possible causes for the symptom and designs targeted tests to rule each one out -- it proceeds by hypothesis testing, not by scattering print statements through the program.
Program Slicing narrows the search to the specific statements that could influence a chosen variable's value (a "slice") -- it filters which code is considered rather than instrumenting the program with prints.