📝
ArkyEdu TIC
RO Solve Interactive
Grade 8 · Olympiad / Prep · 45 min · 100p (10p ex officio)

Grade 8 High-School CS Prep Exam with Rubric: 1D Arrays, Sorting & Binary Search (100 pts)

Quick Summary & Key Points:

High-school CS prep paper (100 pts): 0-based C++ array bounds (`0..n-1`), flag variable verification (`ok = 1`), adjacent pair loop limits `i < n - 1`, and binary search `O(log₂ n)` step bounds.

Theory Snapshot: `int v[5]` has valid indices `0, 1, 2, 3, 4` (never touch `v[5]`). Comparing `v[i]` with `v[i+1]` requires `i < n - 1`. Binary search requires a sorted array and runs in O(log₂ n) comparisons.

1. Part I · 1 (18p)

Given `int v[6] = {10, 20, 30, 40, 50, 60};`, what is `v[2] + v[5]`?

Answer & Explanation: B) 90 — C++ indexing starts at 0: `v[2]=30` and `v[5]=60`, so `30 + 60 = 90`.

2. Part I · 2 (18p)

In a sorted array of `1,024` elements, roughly how many halving steps does Binary Search take at most?

Answer & Explanation: C) 10–11 steps (since 2¹⁰ = 1,024) — Since `2^10 = 1,024`, binary search halves the range in only 10–11 steps (`O(log₂ n)`).

3. Part II · 1 (18p)

What does the code below output for the 4-element array `a`?

int a[4] = {5, 12, 8, 20};
int m = a[0];
for (int i = 1; i < 4; i++) {
    if (a[i] > m) m = a[i];
}
cout << m;

Answer & Explanation: 20 — `m` updates 5 → 12 → 12 → 20, printing the array maximum `20`.

4. Part II · 2 (18p)

True or False: Binary Search works accurately even on an unsorted array.

Answer & Explanation: B) False — False! Binary Search strictly requires a sorted array so it knows which half to discard.

5. Part III (18p)

When checking adjacent pairs `if (v[i] > v[i+1])` on a `0..n-1` array, what is the safe upper bound in `for (int i = 0; i < ...; i++)`?

Answer & Explanation: n-1 — If `i` reached `n - 1`, `v[i + 1]` would read out-of-bounds `v[n]`. Stop strictly at `i < n - 1`.

Official 100-Point Grading Rubric (Grade 1–10)

Section Evaluated Competency Points
Part I (2 × 18 pts) 0-based indexing & O(log₂ n) binary search 36p
Part II (2 × 18 pts) Array maximum trace & sorted precondition 36p
Part III (18 pts) Preventing out-of-bounds `v[i+1]` with `i < n - 1` 18p
Ex officio Baseline points 10p
TOTAL (Grade = Score / 10) 100p

More Worksheets & Related Links