REVISION AND PRACTICE

Week 4 revision and practice

1 min read

Try each question before opening the explained answer. Use the labs to test your reasoning, then explain why the method works, what it counts and which assumptions it needs.

Try it yourself

Six distinct cards: how many unordered pairs? Show two ways to calculate it.

Show explained answer

6 × 5 ÷ 2 = 15, or 5 + 4 + 3 + 2 + 1 = 15. Remove self-pairs and keep each reversed pair only once.

Try it yourself

A nine-card dataset splits into bins of 4, 3 and 2. How many within-bin pair checks remain?

Show explained answer

6 + 3 + 1 = 10, compared with 36 unbinned checks. Add nine placement visits separately when describing the work.

Try it yourself

A date bin uses the exact birthday key. How can you count matching pairs without comparing every pair in the bin?

Show explained answer

As each new card arrives, add the number of earlier cards with that same key to PairCount, then increase that key’s count. In a group of three matching dates the additions are 0, 1 and 2, totalling 3. This is a stated extension using per-key counts.

Try it yourself

A class has two January birthdays, both January 8, and two March birthdays, both March 8. How many matching pairs?

Show explained answer

Two: one January pair and one March pair. Do not compare the two months merely because their day numbers agree.

Try it yourself

Every bill in a two-bill customer bin comes from the same shop. Does that meet the lecture’s definition?

Show explained answer

Yes. At least two observed bills and one distinct shop meet it. This does not predict unobserved visits.

Try it yourself

A developer bins bills by BillAmount to find customer loyalty. Is that enough?

Show explained answer

No. Loyalty is about all visits of one customer and their shops, not spending size. Group by customer.

Try it yourself

After checking an outer row X, the code returns X to the unprocessed table. What can go wrong?

Show explained answer

X may be selected again, causing repeated pairs or even nontermination. Processed outer rows must stay separate unless the algorithm has another explicit progress mechanism.

Try it yourself

What happens to the full result when the score-card order is reversed?

Show explained answer

Exact complete birthday and city/Maths pair sets remain the same. Early-stop work and the first pair encountered can change.

Try it yourself

Does two nested loops always imply n squared visits?

Show explained answer

No. A loop over disjoint bins followed by a scan of each bin’s own contents visits each record once overall. Count the actual visits. All pairs within one size-n group does grow quadratically.

Try it yourself

Why is the total-band partner finder not guaranteed to be optimal?

Show explained answer

It ignores some cross-band pairs, uses a chosen subject-strength heuristic, and lists candidates without solving an exclusive global assignment objective.

Try it yourself

For a 4-by-3 cross-group search, how many candidate pairs are checked?

Show explained answer

4 × 3 = 12. These are pairs across two separate groups; do not divide this product by 2.

Try it yourself

In a pronoun search, does restoring the total number of cards satisfy an exact restoration contract?

Show explained answer

No. Their values, original order and marked position must also survive. The same count can hide a scrambled paragraph.

Try it yourself

Why is a correct candidate at position 40 insufficient to prove the rule generally correct?

Show explained answer

A few successful examples do not rule out counterexamples. Positions 55 and 61 expose failures of the nearest explicit name rule.

Try it yourself

A condition is A OR B, but the body increases both a noun counter and a verb counter. What should you inspect?

Show explained answer

Which condition should control each update. Shared entry into the body does not mean both categories apply; separate conditional updates are needed.

Try it yourself

For reluctant, what is true after processing seven letters?

Show explained answer

The prefix relucta contains 3 vowels and 4 consonants. Their sum is 7. The next letter position is 8.

Try it yourself

What happens if a word procedure swaps its return values but the caller still expects (vowels, consonants)?

Show explained answer

The caller interprets the counts incorrectly. Return order is part of the interface contract, just like parameter order.

Try it yourself

A score record is valid but two month labels have different spellings. Is a type check alone enough?

Show explained answer

No. Meaningful comparison also needs consistent representation or normalization. Jul and July denote the same month.

Try it yourself

Which lesson from this week helps in every algorithm trace?

Show explained answer

State exactly what the variables mean, what one step processes, how progress happens, when it stops, and what the procedure promises to preserve.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑