Introduction to Algorithms, Programming, and Compilers MCQ Practice

Question 1 of 10

A student is describing how to pack one field-trip first-aid pouch. Which description is the clearest algorithm?

  1. A. Pack the pouch the usual way.
  2. B. Make sure the pouch is ready.
  3. C. Place a bandage pack in the pouch, place an antiseptic wipe on top of it, zip the pouch, and clip it to the backpack.
  4. D. Do whatever is needed so someone can treat a scrape.

Question 2 of 10

A museum replica must be dusted before a glass case is lowered over it. The case must be lowered before the lock is fastened, and the lock must be fastened before visitors are admitted. Which sequence satisfies all these requirements?

  1. A. Dust replica → lower case → fasten lock → admit visitors.
  2. B. Lower case → dust replica → fasten lock → admit visitors.
  3. C. Fasten lock → dust replica → lower case → admit visitors.
  4. D. Admit visitors → dust replica → lower case → fasten lock.

Question 3 of 10

A playlist starts with one song titled Dawn. Follow these steps once, in order: (1) append Dusk after the current playlist; (2) insert Noon at the beginning; (3) remove the last song. What songs remain, in order?

  1. A. Noon, Dawn
  2. B. Dawn, Dusk
  3. C. Noon, Dusk
  4. D. Noon, Dawn, Dusk

Question 4 of 10

Three folders sit in a stack, top to bottom: Math, Art, Choir. Follow these steps once, in order: (1) move the top folder to the bottom; (2) swap the new top folder with the folder directly beneath it. What is the final top-to-bottom order?

  1. A. Art, Choir, Math
  2. B. Choir, Art, Math
  3. C. Math, Choir, Art
  4. D. Choir, Math, Art

Question 5 of 10

A journalism club laptop has only a plain text editor. No compiler or IDE is installed. Which task can a student complete on that laptop tonight?

  1. A. Generate a newly compiled Java program and run it.
  2. B. Type and save the Java source as a text file to compile later on a lab computer.
  3. C. Have the editor certify that the algorithm matches the assignment.
  4. D. Skip compilation forever, because a saved text file is already a running Java program.

Question 6 of 10

A Java program that estimates leftover field-trip seats compiles with no reported errors. Which next action is an example of testing?

  1. A. Changing the font in the text editor.
  2. B. Running the program with a planned number of reserved seats and comparing the printed leftover count with a predicted result.
  3. C. Renaming the source file without opening it.
  4. D. Assuming the leftover count is correct because compilation succeeded.

Question 7 of 10

A compiler reports errors on three lines of a newly written program. After the student corrects the first reported problem, what is a sensible next step?

  1. A. Run the unfinished new version immediately, because one correction is enough.
  2. B. Delete the source file so the compiler has nothing to check.
  3. C. Compile the corrected source again and address any remaining reported errors before running the new program.
  4. D. Ignore later compiler messages, because they cannot refer to real problems.

Question 8 of 10

Which observation most clearly indicates a syntax error?

public class StageCrew
{
  public static void main(String[] args)
  {
    System.out.println("Stand ready");
  1. A. The program finishes and prints 18 when the intended result is 24.
  2. B. The compiler rejects the source because a required closing brace is missing.
  3. C. Execution stops when an unhandled exception occurs while opening a missing file.
  4. D. The programmer later decides a different algorithm would be clearer.

Question 9 of 10

A studio-rental program should charge $8 times the number of hours. It compiles and runs without exceptions, but it divides 8 by the hours instead of multiplying. Which test most directly exposes the described logic error?

  1. A. Compile the source again without running it.
  2. B. Test 1 hour and observe 8, which matches both operations.
  3. C. Change the editor's color theme.
  4. D. Test 4 hours and compare the actual result 2 with the expected 32.

Question 10 of 10

Which statement correctly distinguishes a logic error from a run-time exception?

  1. A. A logic error is reported by the compiler before any program is produced; a run-time exception is a missing semicolon.
  2. B. A logic error lets the program finish with an incorrect result for the intended task; a run-time exception interrupts execution after the program has started.
  3. C. Both are detected only by the compiler and never during testing or execution.
  4. D. A run-time exception means the algorithm is automatically correct.