Free Practice Quiz Question List

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.

20 questions
01
Choose one
1 point

A program must print every item in a list whose contents are already available. Which control structure is generally the clearest choice?

  1. A

    Use a while loop because every loop should depend on a condition.

  2. B

    Use a for loop because the program processes each item in a known collection.

  3. C

    Use a conditional because collections cannot be processed by loops.

  4. D

    Use a method because loops cannot access array elements.

02
Choose one
1 point

In the best_student algorithm, why does the function first check whether the students array is empty?

  1. A

    It ensures every student is compared twice.

  2. B

    It sorts the students before calculating averages.

  3. C

    It prevents accessing the first element of an empty array.

  4. D

    It guarantees that all students have the same number of scores.

03
Choose one
1 point

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?

  1. A

    A syntax error

  2. B

    A runtime error

  3. C

    A performance problem

  4. D

    A logic error

04
True or false
1 point

A while loop can continue indefinitely if no part of its body changes the condition that controls termination.

  1. A

    True

  2. B

    False

05
True or false
1 point

A regression test is designed to ensure that a previously discovered bug does not silently return after later code changes.

  1. A

    True

  2. B

    False

06
Fill in the blank
1 point

In the best_student algorithm, the statement that best refers to the highest-scoring student examined so far is an algorithmic .

07
Fill in the blank
1 point

If a Car contains an Engine but is not a type of Engine, the design is usually modeled with rather than inheritance.

08
Written response
1 point

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?

09
Written response
1 point

What is the time complexity of a method that makes one pass through an array of nn values and performs constant work for each value?

10
Choose all
1 point

Which two choices represent useful categories of tests for the best_student method? Select all correct choices.

  1. A

    A normal case with several valid students

  2. B

    A case chosen only because it uses a variable with a descriptive name

  3. C

    A boundary case involving a minimum or maximum score

  4. D

    A case that omits the expected result

11
Choose all
1 point

Which two practices support well-designed, testable methods? Select all correct choices.

  1. A

    A method should combine every related operation into one large procedure.

  2. B

    A method should generally have one clear responsibility.

  3. C

    A method should avoid parameters and return values whenever possible.

  4. D

    A method can often be tested directly with several small inputs.

12
Choose one
1 point

Which design choice best demonstrates an appropriate use of inheritance?

  1. A

    A Car should inherit from Engine because it contains one.

  2. B

    A method should inherit from every method it calls.

  3. C

    A GraduateStudent can inherit from Student because it is a specialized kind of Student.

  4. D

    An array should inherit from each value it stores.

13
Choose one
1 point

A program uses nested loops in which each loop can visit all nn elements of the same array. Which time-complexity category most commonly describes this pattern?

  1. A

    O(1)O(1)

  2. B

    O(n2)O(n^2)

  3. C

    O(log⁡n)O(\log n)

  4. D

    O(nlog⁡n)O(n \log n)

14
Choose one
1 point

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 9595 receives the A grade?

  1. A

    Check score≥70score \ge 70, then score≥80score \ge 80, then score≥90score \ge 90.

  2. B

    Check score≥90score \ge 90, then score≥80score \ge 80, then score≥70score \ge 70.

  3. C

    Check only whether score>0score > 0.

  4. D

    Check score≥80score \ge 80, then score≥90score \ge 90, then score≥70score \ge 70.

15
True or false
1 point

True or false: A while loop can run indefinitely if no statement inside the loop changes the condition that controls whether it continues.

  1. A

    True

  2. B

    False

16
Choose one
1 point

A program must calculate the total of every value in an already available list. Which control structure is the most appropriate choice?

  1. A

    Use a while loop because the collection might contain an unknown number of items.

  2. B

    Use a for loop because the program must process each item in a known collection.

  3. C

    Use a conditional instead of any loop.

  4. D

    Use a class because collections require objects.

17
Written response
1 point

During debugging, after forming a hypothesis and gathering focused evidence, what short phrase describes the recommended kind of code change?

18
Choose one
1 point

In the Student example, why is a class useful when many student objects share the same structure and operations?

  1. A

    A class stores only unrelated global variables.

  2. B

    A class is used only to repeat a loop.

  3. C

    A class bundles related data and behavior.

  4. D

    A class automatically sorts every array it contains.

19
Written response
1 point

A method makes one pass through a list of nn values and performs constant work for each value. What is its time complexity?

20
Open ended
1 point

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.