Introduction to Algorithms, Programming, and Compilers MCQ Practice

Question 1 of 10

A student is writing directions for watering one classroom plant. Which description is the clearest algorithm?

  1. A. Water the plant the right way.
  2. B. Make sure the plant gets enough water.
  3. C. Fill the watering can from the sink, pour until the soil is damp, then empty leftover water back into the sink.
  4. D. Take care of the plant as needed.

Question 2 of 10

A gym locker must be opened before a towel is placed inside. The towel must be placed before the locker is closed, and the locker must be closed before the student leaves the locker room. Which sequence satisfies all these requirements?

  1. A. Open locker → place towel → close locker → leave locker room.
  2. B. Place towel → open locker → close locker → leave locker room.
  3. C. Open locker → close locker → leave locker room → place towel.
  4. D. Leave locker room → open locker → place towel → close locker.

Question 3 of 10

A necklace starts with three beads in this left-to-right order: amber, cream, jade. Follow these steps once, in order: (1) move the rightmost bead to the far left; (2) swap the two rightmost beads. What is the final order?

  1. A. Jade, amber, cream.
  2. B. Jade, cream, amber.
  3. C. Cream, jade, amber.
  4. D. Amber, jade, cream.

Question 4 of 10

A hiking trail marker starts at kilometer 5. Follow the numbered steps in the table exactly once, in order. What is the final kilometer reading?

Step Action
1 Walk 4 kilometers farther (add 4)
2 Double the current kilometer reading
3 Walk 2 kilometers back toward the start (subtract 2)
4 Halve the current kilometer reading
  1. A. 6
  2. B. 8
  3. C. 9
  4. D. 16

Question 5 of 10

Which statement best describes the role of a compiler when a student prepares a Java program to run?

  1. A. It prints the program's output for every possible input.
  2. B. It translates source code into a form that can be executed and reports errors that prevent a successful translation.
  3. C. It replaces the need to test the finished program.
  4. D. It is the only program that can open a source-code file.

Question 6 of 10

A computer lab has a plain text editor, a separate Java compiler, and a way to run compiled programs. No IDE is installed. Which statement is true?

  1. A. The student cannot write Java source code without first installing an IDE.
  2. B. The student can write the source in the text editor, compile it with the compiler, and then run the compiled program.
  3. C. The compiler will automatically rewrite every incorrect algorithm while translating.
  4. D. Running the program is possible only if the source was last opened inside an IDE.

Question 7 of 10

A student successfully compiles a Java program that prints today's cafeteria menu. The student then edits the source so it prints tomorrow's menu, but immediately runs the previously compiled program without compiling again. What is the most likely result?

  1. A. Tomorrow's menu appears, because editing a source file instantly updates every compiled copy.
  2. B. The compiler automatically recompiles whenever a file is saved, even if it is not asked to.
  3. C. Today's menu may still appear, because the program that ran was built from the older source.
  4. D. The program cannot run at all until an IDE is installed.

Question 8 of 10

A student writes the Java statement below. The compiler rejects it, and no program starts executing. What type of error is described?

System.out.println("Open the greenhouse")
  1. A. A logic error that can be found only by comparing output with expected results.
  2. B. A run-time exception that occurs after the program finishes normally.
  3. C. A syntax error.
  4. D. No error, because a human reader can still understand the intended message.

Question 9 of 10

A program is intended to compute leftover concert tickets after a sale. It compiles and finishes without an exception, but it adds tickets sold to tickets available instead of subtracting. The test results below are observed. Which classification best describes the mistake?

Available Sold Expected leftover Actual output
40 12 28 52
25 5 20 30
  1. A. A logic error.
  2. B. A syntax error.
  3. C. A run-time exception that stopped the program.
  4. D. No error, because the program produced a number.

Question 10 of 10

A Java program compiles successfully. While it is running, it attempts to divide an integer by zero and an unhandled exception stops execution. Which statement is most accurate?

  1. A. The compiler must have missed a required semicolon.
  2. B. An exception occurred at run time.
  3. C. The program never began executing.
  4. D. The program necessarily produced its intended final result.