Loading...
Break a task into responsibilities, connect them through inputs and outputs, then locate the decisions that change the execution path. A list of routine names is not yet a complete algorithm.
What you'll be able to do
A school booking system must prevent overlapping use of a room, rather than merely display a colourful timetable. Identify its inputs, required state changes and observable outcomes. A useful decomposition might include parse_request, validate_request, find_conflicts, save_booking and display_result. Each part should have one clear responsibility and a defined interface.
Separate a subproblem from the proposed solution technology. “Use a database” names a possible implementation choice, while “detect an overlapping booking” identifies required behaviour. A structure chart can show which routines call which, but the order, branch conditions and data passed between them still need to be specified.
Validation must establish that the finish time is later than the start before the conflict calculation trusts the interval. Conflict checking must happen before accepting and storing a booking. If checking and storing are separate in a shared system, their combined operation also needs suitable coordination so two requests cannot both claim the same time.
Subroutines communicate through parameters and results rather than hidden assumptions about unrelated state. A Boolean validation result might choose whether to continue or display a clear error. Trace a request through both a successful path and a rejected path, recording which state changes occur. Rejected input should not leave a partly stored booking.
For half-open intervals [start,end), a proposed booking overlaps an existing one when proposed_start < existing_end AND proposed_end > existing_start. This convention permits one booking to start exactly when another ends. Using OR would classify many non-overlapping intervals as conflicts. The boundary convention is part of the problem definition.
Construct test cases before trusting the expression: entirely before, entirely after, touching at either endpoint, contained within and surrounding an existing booking. Logical thinking follows the decisions and their consequences, not just the syntax of IF. A flowchart’s decision branches should be labelled by conditions or outcomes so that each permitted input follows a defined path.
def overlaps(start, end, existing_start, existing_end):
return start < existing_end and end > existing_start
print(overlaps(9, 10, 10, 11))
print(overlaps(9, 11, 10, 12))Scroll horizontally to see the full code or table.Attempt the task before opening its worked response. Record each change of state, explain the rule used, and check the result against the original requirements. Code examples labelled Python 3 use that language’s conventions; pseudocode states its own assumptions.
Common mistakes to avoid
Key takeaways
Test yourself
Answer a few questions, then review anything you missed.
Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.