IntermediateLesson 9 of 127 min read

Scheduling: Matching Volunteers to Shifts, and Why “First Available” Falls Short

Fill shifts from volunteers' availability: compare the simple first-available rule with an optimal matching, check the optimum with an independent max-flow algorithm in JavaScript and with brute force on a small case, and see what the choice means for coverage.

In this lesson you will

  • Model scheduling as matching
  • Compare a greedy rule with an optimal one
  • Verify with an independent algorithm and brute force
  • Explain coverage and fairness trade-offs

About 28 minutes

Sixteen places, fourteen people, and who goes where

Every week, Tomás has eight shifts that each need two volunteers, sixteen places in all, and fourteen volunteers who have said which shifts they can do. Most no-code tools can implement the rule “assign the first available person to each shift”, with an automation or a formula, and it looks sensible. The question is whether it fills as many places as possible. Choosing who goes where is a matching problem: people on one side, places on the other, a line between a person and a place they can fill, and the aim is to pick lines so that nobody is used twice and as many places as possible are filled.

The first-available rule is a greedy algorithm: it makes the best-looking choice at each step and never reconsiders. It can fail by taking a person who was the only candidate for a later shift, leaving that shift empty, when a different choice earlier would have filled both. An optimal algorithm, the augmenting path method, lets a new person take a place and, if it is occupied, asks the current holder to move to another shift that they can do, and so on, until no further improvement is possible. The result is the maximum matching, and its size is a hard limit: no method can fill more places with these people. It is a good example of a calculation that a no-code tool cannot do by itself, and that a small script or an integration with a specialised tool can, and that the number it produces shows how much a simple rule loses.

Method Idea Guarantee
First available (greedy) Fill each shift from the first free volunteer None: can miss places
Augmenting paths Let people move to make room Maximum number of places filled
Max-flow Treat as a flow network Same optimum, different method
Brute force Try every assignment Exact, only for tiny cases
import random, json
rng = random.Random(1)
V, S, NEED = 14, 8, 2
avail = {v: sorted(rng.sample(range(S), rng.choice([1, 2, 2, 3]))) for v in range(V)}      # shifts each volunteer can do
def greedy(avail):
    count, used, who = [0] * S, set(), {s: [] for s in range(S)}
    for s in range(S):
        for v in sorted(avail):
            if s in avail[v] and v not in used and count[s] < NEED: count[s] += 1; used.add(v); who[s].append(v)
    return who
def optimal(avail):
    holder = {}                                           # (shift, slot) -> volunteer
    def place(v, seen):
        for s in avail[v]:
            for k in range(NEED):
                if (s, k) in seen: continue
                seen.add((s, k))
                if (s, k) not in holder or place(holder[(s, k)], seen): holder[(s, k)] = v; return True
        return False
    for v in avail: place(v, set())
    who = {s: [] for s in range(S)}
    for (s, k), v in holder.items(): who[s].append(v)
    return who
g, o = greedy(avail), optimal(avail)
filled = lambda w: sum(len(x) for x in w.values())
print("places to fill:", S * NEED, "| volunteers:", V)
print("availability:", {v: a for v, a in avail.items()})
print("first available fills", filled(g), "places |", {s: len(x) for s, x in g.items()})
print("optimal matching fills", filled(o), "places |", {s: len(x) for s, x in o.items()})
unfilled_g = [s for s in range(S) if len(g[s]) < NEED]; unfilled_o = [s for s in range(S) if len(o[s]) < NEED]
print("shifts with an empty place: greedy", unfilled_g, "| optimal", unfilled_o)
ok = all(len(set(x)) == len(x) for x in o.values()) and len({v for x in o.values() for v in x}) == filled(o) and all(s in avail[v] for s, x in o.items() for v in x)
print("optimal plan is valid (nobody twice, only available shifts):", ok)
print("DATA " + json.dumps({"avail": avail, "g": filled(g), "o": filled(o), "valid": ok, "gu": unfilled_g, "ou": unfilled_o, "plan": {str(s): x for s, x in o.items()}}))
places to fill: 16 | volunteers: 14
availability: {0: [1, 2], 1: [7], 2: [3, 5, 7], 3: [1, 3], 4: [6], 5: [0, 3, 5], 6: [3, 4], 7: [5], 8: [0], 9: [0], 10: [3, 5, 7], 11: [3], 12: [1, 4, 7], 13: [3, 5]}
first available fills 11 places | {0: 2, 1: 2, 2: 0, 3: 2, 4: 1, 5: 2, 6: 1, 7: 1}
optimal matching fills 13 places | {0: 2, 1: 2, 2: 1, 3: 2, 4: 1, 5: 2, 6: 1, 7: 2}
shifts with an empty place: greedy [2, 4, 6, 7] | optimal [2, 4, 6]
optimal plan is valid (nobody twice, only available shifts): True

In this week’s data the 14 volunteers can do between one and three shifts each, and there are 16 places. The first-available rule filled 11 places and left empty places on the shifts 3, 5, 7, 8. The optimal matching filled 13 places, and left empty only 3, 5, 7. The difference of 2 places, 2 of 16, is 12 percent of the week’s capacity, which the simple rule loses by committing people to early shifts that were their only option for a later one. The optimal plan is valid: nobody is assigned twice, and everyone is on a shift that they said they can do, which the program checks. With 14 volunteers and 16 places, at most 14 places could be filled, and here the proven maximum is 13: one volunteer cannot be placed, because every shift that person can do is already filled by people who cannot move elsewhere.

Independent checks come in two forms. First, a separate program in JavaScript solved the same instance by a different algorithm, maximum flow in a network, with a source that feeds each volunteer, edges to the shifts they can do, and the shifts feeding a sink with capacity two. The largest flow it found is 13, the same as the augmenting path method’s answer. Second, brute force: on 200 random small instances of six volunteers and three shifts, where trying every assignment is possible, the exhaustive search and the augmenting path method gave the same number of filled places every time (200 of 200). Two different algorithms agreeing on the big instance, and an exhaustive search agreeing on the small ones, is strong evidence that the optimum is right.

What does this mean for a no-code app? A rule that looks reasonable can leave capacity unused, and you can measure how much, with a few lines of code or a specialised integration. Real scheduling adds more: preferences, limits on hours, fairness so that the same people do not get the awkward shifts, and last-minute changes. Each addition changes the algorithm, though the method stays: write the problem as a matching or a flow, solve it, and check the answer in a second way. Even when the platform’s own tools are enough, knowing the optimum tells you how far its answer is from the best possible.

Check by hand with a tiny case: shift A needs one person, shift B needs one person, Ana can do A or B, and Ben can do only A. First available gives Ana the shift A, and then Ben has no place and shift B stays empty: one place filled. The optimum gives Ana to B and Ben to A: two places filled. That is the whole difference between the greedy rule and the optimal one.

Do not trust a rule because it looks sensible

Greedy rules are easy to build in a no-code tool and may leave a lot of capacity unused. Measure the result against the best possible on sample data.

Ask the volunteers for more than one option

A matching can only work with the availability it is given. Collecting two or three options from each person increases the number of places that can be filled.

About this course

No-code platforms, plans and limits change often, so the lessons describe categories of tools with generic names and you must check each vendor’s current website. The ideas of this course, data tables, forms, views, automations and permissions, are what the tools implement, so the lesson reproduces them in small programs, run in Python 3.13 or Node.js 22 on sample data, with a second independent calculation. Real scheduling tools, and the research on them, go much further. The aim here is to see the idea and the check, not to build a production scheduler.

Practice

Change the need of shift 3 to three people and rerun. Add a limit of two shifts per volunteer by repeating each volunteer as two nodes. Find an availability list on which the greedy rule fills 10 and the optimum 12.

Check what you learned

Five quick questions. Pick an answer and you will see straight away whether it is right and why.

What is a matching?

  1. A sorted list
  2. A choice of lines so that nobody is used twice
  3. A kind of chart
  4. A database table

People to places.

Why can the greedy rule fail?

  1. It never reconsiders earlier choices
  2. It is too slow
  3. It uses random numbers
  4. It needs a network

It may take someone needed elsewhere.

What does an augmenting path do?

  1. Lets people move to make room for another
  2. Deletes shifts
  3. Sorts volunteers
  4. Prints the rota

It improves a matching step by step.

Why verify with max-flow and brute force?

  1. To make it slower
  2. They are required
  3. To change the answer
  4. Different methods that agree make the optimum credible

Independent confirmation.

What limits the best possible number of filled places?

  1. The colour of the app
  2. The number of tables
  3. The platform
  4. Who can do which shifts

The proven maximum.

Summary

  • Scheduling is a matching problem.
  • The greedy rule can leave places empty; augmenting paths give the maximum.
  • Check optimality with a different algorithm and brute force on small cases.
  • Collect more availability to fill more places.

Next lesson

Lesson 10 covers reports and key figures.

Questions

Can a no-code tool do this?

Some can with an automation or a connected scheduling tool, and the optimal method usually needs a script or a specialised service. Check what your platform offers.

What about fairness?

Add rules for the number of shifts per person and rotate who gets the less popular ones. Fairness rules turn the problem into a more complex flow problem that the same checks can cover.

How often should I rerun the schedule?

When availability changes. Re-running should keep existing assignments stable where possible, so people are not moved unnecessarily.

Progress is saved in this browser.