Back to Challenge Set 19

Question Set 11

Difficulty  

divider

What This Is

Six exam-style questions through Activity 2.10, weighted toward searching. These sets are cumulative, so anything earlier is still fair game.

Question 4 is in exam notation, and its list starts at index 1. Read which notation a question is in before you count anything.

How to Do This One

  • Set a timer for 11 minutes before you start.
  • When the timer ends, stop. Mark anything unfinished as unfinished — that is real information, not a failure.
  • Work them out. Do not run the code. On exam day there is no computer.
  • For each question, also write sure or unsure. This is graded on completion, so an honest unsure costs you nothing and tells us both where to look.

Guessing beats leaving it blank. There is no penalty for a wrong answer on the AP exam, so a blank is a guaranteed zero where a guess is not.


The Questions

Four have exactly one correct answer, one asks you to select all that apply, and the last is about data or the impact of computing rather than about code.


Question 1

What does the following C# display?

Question 1
int[] items = { 4, 9, 4, 7 };
Console.WriteLine(Find(4));
Console.WriteLine(Find(5));
int Find(int target)
{
for (int i = 0; i < items.Length; i++)
{
if (items[i] == target)
{
return i;
}
}
return -1;
}
  • (A) 0 then 0
  • (B) 2 then -1
  • (C) 0 then -1
  • (D) 0 then 4

Question 2

A sorted list holds 16 items. What is the greatest number of comparisons a binary search could need to find an item, or to find out that it is not there?

  • (A) 4
  • (B) 5
  • (C) 8
  • (D) 16

Question 3 — Select all that apply

Which of these are true of binary search?

  • (A) It requires the list to be sorted
  • (B) It always finds the target in exactly one comparison
  • (C) Each comparison rules out about half of what is left
  • (D) It works on any list, sorted or not
  • (E) On an unsorted list it may report a value as missing when it is there

Question 4

This is written in exam notation. What does it display?

Question 4
aList ← [3, 6, 9, 12, 15]
i ← 1
total ← 0
REPEAT UNTIL(i > LENGTH(aList))
{
total ← total + aList[i]
i ← i + 2
}
DISPLAY(total)
  • (A) 45
  • (B) 18
  • (C) 24
  • (D) 27

Question 5

A correct binary search method is given an array that is not sorted. Which is most likely to happen?

  • (A) It stops with an index error
  • (B) It sorts the array first, then searches it
  • (C) It may report a value as missing even though it is there
  • (D) It always returns index 0

Question 6 — Data and Impact

A city publishes its bus arrival times as open data, so anyone can build an app with it. Residents without a smartphone or home internet cannot use any of those apps. The gap between those two groups is best described as:

  • (A) The digital divide
  • (B) Data compression
  • (C) Metadata
  • (D) A heuristic

Submit

Six answers, each marked sure or unsure, plus how far you got when the timer went off.

Start the Timer