Algorithmic Problem Solving: From Requirements to Checked Steps

Algorithmic problem solving turns a stated need into precise steps you can check before writing a program. You use it when a task involves calculations, choices, or repeated actions. The central challenge is deciding exactly what the steps must accomplish for every allowed input, including unusual cases. A procedure that works for one convenient example may still fail to meet the requirements.

Specify the task

A problem specification states the allowed inputs, the required outputs, and the conditions connecting them. Write these down before choosing operations. Include units, permitted ranges, and any assumptions that affect the result.


For example, arranging transport requires more information than a student count. You need the capacity of each vehicle and whether the goal is to minimize vehicles, empty seats, or cost. Those goals can lead to different procedures. Resolve an ambiguous requirement rather than silently choosing an interpretation.


Separate a requirement from a proposed method. Saying that every student needs a seat describes the required result. Saying to divide by vehicle capacity proposes part of a method. This separation lets you judge a method against the task it is supposed to solve.

Build manageable steps

Decomposition means breaking a problem into smaller tasks whose results combine to solve the original problem. Each smaller task should have a clear purpose and produce information that another step can use.


Four connected boxes show specifying requirements, breaking down the task, forming steps, and checking cases.


Suppose you must place nn objects into the fewest containers, each holding at most cc objects. Assume that nn is a nonnegative integer, cc is a positive integer, and objects cannot be split. Find the number of full containers and the number of objects left over. The floor notation gives a convenient calculation:


q=⌊nc⌋,r=n−cq.q=\left\lfloor\frac{n}{c}\right\rfloor,\qquad r=n-cq.


Then choose the required number of containers, bb:


b={q,r=0,q+1,r>0.b=\begin{cases} q,&r=0,\\ q+1,&r>0. \end{cases}


Example: With 18 ribbons and space for 7 ribbons per envelope, there are 2 full envelopes and 4 ribbons left over. You therefore need 3 envelopes.


Express the steps in plain language or pseudocode. Identify which steps happen in sequence, which depend on a condition, and which repeat. If a step repeats, state what changes each time and when repetition ends.



Check the procedure against cases

Follow the steps manually and record changing values. Use the value produced by the latest completed step when a later step depends on it. This catches errors such as repeatedly using the original quantity instead of the remaining quantity.


Choose cases for a reason. For the container procedure, the following cases check different decisions:


Case

Required behaviour

Mistake it can expose

No objects

Return zero containers

Adding a container unconditionally

Exactly full containers

Add no extra container

Treating zero remainder as leftover objects

Some objects left over

Add one container

Discarding the remainder


Test values on both sides of a decision boundary, including equality. Also calculate the expected output independently of the proposed steps; otherwise, the same mistake can affect both your method and your check.



For the container procedure, the remainder satisfies 0≤r<c0\leq r<c. A zero remainder needs no extra container; a positive remainder fits into exactly one more. This explains why the two cases cover every allowed input.

What to remember

  • State inputs, outputs, units, and assumptions before choosing operations.
  • Break the task into smaller tasks with useful results.
  • Make choices, updates, and stopping conditions explicit.
  • Check boundaries and explain why the procedure covers the allowed inputs.

Example: Plan buses without adding an unnecessary trip

A school hires identical buses with 28 passenger seats each. Every student needs a seat, and no other passengers travel. The school wants the fewest buses and the number of empty passenger seats. The student count nn may be any nonnegative integer. A trace records the intermediate values produced as you follow a procedure for a particular input.


a) Formulate a procedure that takes nn and returns both the required number of buses and the number of empty seats. Include the case of no students.


First, separate the task into counting full buses, checking for leftover students, and calculating unused seats. Add an extra bus only when students remain after filling the full buses.

  1. Read the nonnegative integer student count nn.
  2. Calculate the full-bus count q=⌊n/28⌋q=\lfloor n/28\rfloor.
  3. Calculate the remaining student count r=n−28qr=n-28q.
  4. If r=0r=0, set the bus count b=qb=q. Otherwise, set b=q+1b=q+1.
  5. Calculate the empty-seat count e=28b−ne=28b-n.
  6. Return bb buses and ee empty seats.

When n=0n=0, both qq and rr are zero. The procedure therefore returns zero buses and zero empty seats, as required.


The final procedure uses the remainder to decide whether another bus is needed, then subtracts occupied seats from the total seats provided.


b) Apply the procedure to 73 students. Find the number of buses and empty passenger seats.


First, calculate the number of full buses:


q=⌊7328⌋=2.q=\left\lfloor\frac{73}{28}\right\rfloor=2.


The full-bus count is ________. These buses seat 28×2=5628\times2=56 students.


Next, calculate the number of students left over:


r=73−28(2)=73−56=17.r=73-28(2)=73-56=17.


There are ________ left after filling the first two buses. Because this count is positive, add one bus:


b=q+1=2+1=3 buses.b=q+1=2+1=3\ \text{buses}.


Finally, the buses provide ________, since 28×3=8428\times3=84. Subtract the occupied seats:


e=84−73=11 empty seats.e=84-73=11\ \text{empty seats}.


The school needs 3 buses with 11 empty passenger seats. Two buses would provide only 56 seats, so three is the smallest bus count that accommodates everyone.


c) Check the bus-count output for 0, 56, and 57 students. Explain what each test checks.


For zero students, calculate q=⌊0/28⌋=0q=\lfloor0/28\rfloor=0 and r=0−28(0)=0r=0-28(0)=0. The zero-remainder branch returns b=0b=0. This checks that the procedure does not hire a bus when nobody travels.


For 56 students, calculate q=⌊56/28⌋=2q=\lfloor56/28\rfloor=2 and r=56−28(2)=0r=56-28(2)=0. The procedure returns b=2b=2. This checks an exact multiple of capacity: no additional bus is needed.


For 57 students, calculate q=⌊57/28⌋=2q=\lfloor57/28\rfloor=2 and r=57−28(2)=1r=57-28(2)=1. The positive-remainder branch returns b=2+1=3b=2+1=3. This checks the first student beyond that exact-capacity boundary.


The expected outputs are 0 buses, 2 buses, and 3 buses, respectively. Together, these tests check the empty input case and both sides of the decision about adding another bus.

A pool booking system receives a requested duration of 1–90 whole minutes and the number of free minutes remaining, from 0 to 90. Accept a request if enough time remains; otherwise reject it. An accepted request reduces the free time, while a rejected request leaves it unchanged. Which specification captures these requirements?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A charging station can allocate at most 21 kWh during a booking period. It processes requests of 8, 17, 6, and 5 kWh in that order. Start the allocated energy at zero. For each request, add it only if the resulting total would be at most 21 kWh; otherwise skip that request and continue. What is the final allocated energy, in kWh, to zero decimal places?

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A game assigns a badge to each integer score from 0 through 100. Apply these rules in order: if the score is below 40, assign bronze; otherwise, if it is below 75, assign silver; otherwise assign gold. Complete the expected badge for every test score using the words bronze, silver, or gold.

ScoreExpected badge
0
39
40
74
75
100

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice