Question 1 of 10
Algorithm M: IF (x > y) { max ← x } ELSE { max ← y }. Algorithm N: max ← x IF (y > max) { max ← y }. For x=4,y=9 which is true?
- A. Both set max to 9.
- B. Neither sets max to 9.
- C. Only M sets max to 9.
- D. Only N sets max to 9.
Algorithm M: IF (x > y) { max ← x } ELSE { max ← y }. Algorithm N: max ← x IF (y > max) { max ← y }. For x=4,y=9 which is true?
List nums is [2,7,7,3]. Count matches to target 7:
count ← 0
FOR EACH value IN nums
{
IF (value = target)
{
count ← count + 1
}
}
DISPLAY (count)
Displayed when target is 7?
Goal: order three-element list ascending by adjacent swaps. After swap of indexes 1 and 2 on [5,1,4] the list is [1,5,4]. Missing next step?
A sums list values. B multiplies a product starting at 1 by each value. For [2,3,4]?
Robot R faces east. Reach G. W = wall.
| Row | C1 | C2 | C3 |
|---|---|---|---|
| R1 | R | G | |
| R2 | W | W | W |
Which algorithm reaches G without a wall hit?
Correct first step to find the maximum in a nonempty list values?
List [3,8,2]. P displays first value > 5. Q displays the maximum. Outputs?
Missing line so count ends as number of matches:
count ← 0
i ← 1
REPEAT LENGTH(data) TIMES
{
IF (data[i] = target)
{
__________________
}
i ← i + 1
}
List [9,4,6]. One left-to-right pass swaps each adjacent out-of-order pair (indexes 1-2 then 2-3 on the updated list). List after that pass?
Best statement about developing algorithms from existing ones?