Developing Algorithms MCQ Practice

Question 1 of 10

F: add then divide by 3. G: divide each by 3 then add. Inputs 3,6,9?

  1. A. Only F yields 6.
  2. B. Only G yields 6.
  3. C. Both yield 6.
  4. D. F yields 18 and G yields 6.

Question 2 of 10

data = [4,4,5,4]. Missing step to count 4s from count ← 0 inside FOR EACH v IN data IF (v = 4)?

  1. A. count ← count + v
  2. B. count ← LENGTH(data)
  3. C. count ← 4
  4. D. count ← count + 1

Question 3 of 10

L=[7,2,9]. Swap indexes 1-2 if out of order, then 2-3 if out of order. L after that pair of checks?

  1. A. [2, 7, 9]
  2. B. [2, 9, 7]
  3. C. [7, 9, 2]
  4. D. [9, 7, 2]

Question 4 of 10

Path U: REPEAT 2 TIMES { MOVE_FORWARD }. Path V: MOVE_FORWARD MOVE_FORWARD. Same start/facing?

  1. A. Different algorithms cannot reach the same cell.
  2. B. They perform the same two forward moves and end equivalently.
  3. C. U moves once and V moves twice.
  4. D. Only V is legal AP CSP pseudocode.

Question 5 of 10

Missing update with best ← vals[1]:

best ← vals[1]
i ← 2
REPEAT (LENGTH(vals) - 1) TIMES
{
  IF (vals[i] > best)
  {
    _______________
  }
  i ← i + 1
}
  1. A. best ← best + 1
  2. B. best ← LENGTH(vals)
  3. C. best ← vals[i]
  4. D. best ← i

Question 6 of 10

Which pair can produce different results while both looping every element of the same nonempty list?

  1. A. Adding each element versus totaling with FOR EACH the same way
  2. B. Two FindMax algorithms initializing from the first element
  3. C. DISPLAY LENGTH(list) versus counting with +1 each visit
  4. D. Summing all elements versus counting how many equal 0

Question 7 of 10

Guard for yes when k evenly divisible by 5?

  1. A. k MOD 5 = 0
  2. B. k MOD 5 = 5
  3. C. k / 5 = 0
  4. D. RANDOM(1, 5) = k

Question 8 of 10

Before [3,1,2], after [1,2,3]. Student claims one adjacent swap. Best response?

  1. A. Correct; three items need only one swap.
  2. B. Incorrect; one adjacent swap cannot produce [1,2,3] from [3,1,2].
  3. C. Correct because LENGTH stayed 3.
  4. D. Incorrect because lists cannot be reordered with swaps.

Question 9 of 10

R uses nested IF for min of two numbers. S assigns first to m then replaces if second smaller. Inputs 8 and 3 both display 3. Illustrates?

  1. A. S is invalid because it uses assignment.
  2. B. Different-looking algorithms cannot share a result.
  3. C. Different algorithms can solve the same problem.
  4. D. Only nested IF may compute a minimum.

Question 10 of 10

sum of elements in total; n = LENGTH(list). Missing final average step?

  1. A. DISPLAY (n / total)
  2. B. DISPLAY (total)
  3. C. DISPLAY (total + n)
  4. D. DISPLAY (total / n) when n > 0