REVISION AND PRACTICE

Week 6 revision and mixed practice

1 min read

Try a procedure with different inputs, then answer before revealing the explanation. Name the input representation, comparison key, tie policy and eligible population.

REAL COURSE DATA · SORT, GROUP AND VERIFY

Unpack paragraph → sentence → word

Follow the selected procedure. Change a field, tie rule or weekday and explain why the result changes.

Ready

CURRENT RECORD / VALUE

Ready to begin

No records have been processed. Start with Next step.

What we remember

Processed
0

Predict the next change. Keep track of which list level, field and position convention the procedure uses.

Try it yourself

For a paragraph represented as lists of character-list words inside sentence lists, what does first(first(P)) return?

Show explained answer

The first word’s character list. One more first reaches its first character, provided each relevant list is non-empty.

Try it yourself

Insert 3 into [1,3,3,5] using strict <.

Show explained answer

The new occurrence goes after the old 3s: [1,3,3,3,5]. IDs or labels would show its relative position among equals.

Try it yourself

Which line must run for every old insertion element, even after a match?

Show explained answer

The line appending the old element to the output. Otherwise existing data may be lost.

Try it yourself

Can you call the insert helper on an unsorted list and assume the result is sorted?

Show explained answer

No. Its contract assumes a sorted input.

Try it yourself

What two properties form the insertion-sort invariant?

Show explained answer

The accumulated result is sorted and contains exactly the occurrences processed so far.

Try it yourself

What does the tutorial’s ≤ do to equal-page insertion order?

Show explained answer

It inserts the new equal-page record before old equals; the lecture’s strict < puts it after them.

Try it yourself

Does sorting 30 items by the copying helper avoid all quadratic work on a favourable order?

Show explained answer

No. It still copies 0+1+…+29 = 435 old elements. Key-comparison work is a separate count.

Try it yourself

A sorted birthday run contains four students. How many equal-neighbour links and all unordered pairs?

Show explained answer

Three equal-neighbour links, but six unordered student pairs.

Try it yourself

What is the usual final-step bug in sorted group counting?

Show explained answer

Forgetting to save the final group after the loop.

Try it yourself

Under the displayed zero-based positional grading code, what are 30-student A/B/C/D counts?

Show explained answer

7,7,8,8. This follows the exact comparisons, not a hand-adjusted quarter split.

Try it yourself

Does first(G) return an ID when G=[AIDs,BIDs,CIDs,DIDs]?

Show explained answer

No. It returns the whole AIDs list.

Try it yourself

Maths A and Physics B: which of the two rules confirms it?

Show explained answer

The looser both-A/B rule confirms it; the at-least-as-good rule rejects it.

Try it yourself

Why does found need resetting for each student?

Show explained answer

A match for an earlier student must not affect whether the next student is found.

Try it yourself

Does exitloop mean return from the procedure?

Show explained answer

No. It ends the nearest enclosing loop, then execution continues outside that loop.

Try it yourself

For the library example, what does first(last(books)) mean?

Show explained answer

The ID of the final, maximum-page book pair, not a page count.

Try it yourself

02201: Kolkata 20:00 Day 1 to Bhubaneswar 03:30 Day 2. Duration?

Show explained answer

450 minutes, or 7 h 30 min.

Try it yourself

A Sunday origin departure reaches a station on Day 2. Which weekday?

Show explained answer

Monday, one day later.

Try it yourself

Why can train and station weekdays disagree without an error?

Show explained answer

They may refer to different events or journey days. Align those meanings first; remaining mismatches should be flagged.

Try it yourself

What is insufficient about checking only whether both station names occur in a route?

Show explained answer

Direction and departure availability matter: source must precede destination, and service must run on the relevant source weekday.

Try it yourself

What does a different-next-call junction clue fail to prove?

Show explained answer

It does not prove physical track branching or that a timed transfer is feasible.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑