A program must print every item in a list whose contents are already available. Which control structure is generally the clearest choice?
9 Programming Problem-Solving Techniques Online Quiz Questions
Use this free practice quiz with 20 questions to review 9 Programming Problem-Solving Techniques, test your knowledge, and prepare for your next test or exam.
In the best_student algorithm, why does the function first check whether the students array is empty?
- A
It ensures every student is compared twice.
- B
It sorts the students before calculating averages.
- C
It prevents accessing the first element of an empty array.
- D
It guarantees that all students have the same number of scores.
A program runs to completion but calculates the wrong average because its update is placed in the wrong branch. What kind of defect is this?
- A
A syntax error
- B
A runtime error
- C
A performance problem
- D
A logic error
A while loop can continue indefinitely if no part of its body changes the condition that controls termination.
- A
True
- B
False
A regression test is designed to ensure that a previously discovered bug does not silently return after later code changes.
- A
True
- B
False
In the best_student algorithm, the statement that best refers to the highest-scoring student examined so far is an algorithmic .
If a Car contains an Engine but is not a type of Engine, the design is usually modeled with rather than inheritance.
A loop executes without crashing, but it adds every value instead of only the even values required by the specification. What defect category describes this problem?
What is the time complexity of a method that makes one pass through an array of n values and performs constant work for each value?
Which two choices represent useful categories of tests for the best_student method? Select all correct choices.
- A
A normal case with several valid students
- B
A case chosen only because it uses a variable with a descriptive name
- C
A boundary case involving a minimum or maximum score
- D
A case that omits the expected result
Which two practices support well-designed, testable methods? Select all correct choices.
- A
A method should combine every related operation into one large procedure.
- B
A method should generally have one clear responsibility.
- C
A method should avoid parameters and return values whenever possible.
- D
A method can often be tested directly with several small inputs.
Which design choice best demonstrates an appropriate use of inheritance?
- A
A Car should inherit from Engine because it contains one.
- B
A method should inherit from every method it calls.
- C
A GraduateStudent can inherit from Student because it is a specialized kind of Student.
- D
An array should inherit from each value it stores.
A program uses nested loops in which each loop can visit all n elements of the same array. Which time-complexity category most commonly describes this pattern?
- A
O(1)
- B
O(n2)
- C
O(logn)
- D
O(nlogn)
A program assigns grades using an if/elif/else chain with thresholds for A, B, and C. Which ordering of threshold checks correctly ensures that a score of 95 receives the A grade?
- A
Check score≥70, then score≥80, then score≥90.
- B
Check score≥90, then score≥80, then score≥70.
- C
Check only whether score>0.
- D
Check score≥80, then score≥90, then score≥70.
True or false: A while loop can run indefinitely if no statement inside the loop changes the condition that controls whether it continues.
- A
True
- B
False
A program must calculate the total of every value in an already available list. Which control structure is the most appropriate choice?
- A
Use a while loop because the collection might contain an unknown number of items.
- B
Use a for loop because the program must process each item in a known collection.
- C
Use a conditional instead of any loop.
- D
Use a class because collections require objects.
During debugging, after forming a hypothesis and gathering focused evidence, what short phrase describes the recommended kind of code change?
In the Student example, why is a class useful when many student objects share the same structure and operations?
- A
A class stores only unrelated global variables.
- B
A class is used only to repeat a loop.
- C
A class bundles related data and behavior.
- D
A class automatically sorts every array it contains.
A method makes one pass through a list of n values and performs constant work for each value. What is its time complexity?
A program sometimes accesses an invalid array index when processing user input. Explain a systematic debugging process you would use to locate and correct the defect, including how you would verify that the correction did not introduce another failure.