Lite / Intelligent Robotic Systems / Week 9
Term assessment: engineering computation, end to end
A teammate's planner is correct, tested and painfully slow, and its chart says it's fast. Can you find every problem in fifteen minutes?
Why should I care?
Real engineering rarely asks one kind of question at a time. This review mixes the whole term: modules and objects, data structures, search and sort, growth rates, numerical methods and honest plots. Treat it as a code review of a teammate's work.
- Review a small program for structure, correctness, efficiency and honest reporting.
- Combine operation counting, search, numerical methods and statistics in mixed problems.
- Explain each fix with a reason grounded in this term's ideas.
Predict
A planner stores visited cells in a list and calls 'cell in visited' for every neighbour. On a 100 × 100 open map, roughly how does that compare with using a set?
- About the same
- Roughly thousands of times more comparisons
- Slightly faster, because lists are simpler
Guess first, then reveal
Thousands of times more. Each membership test scans a list that grows to 10,000 cells, so total work is O(V²) ≈ 10⁸ comparisons instead of O(V) ≈ 4 × 10⁴ hash lookups. One changed line, a huge saving.
Discover
In the Code Lab, review the worked example's planner_report function. List every problem you find under four headings: structure, correctness, efficiency, reporting. Fix them one at a time, re-running the tests after each fix.
What the interactive shows (text version)
The Code Lab review can be done on paper: the 'before' function uses a list membership test inside a loop (O(n²)), divides by zero on an empty list and reports a number without unit, spread or sample size. The fixed version uses a set, checks for empty input, and reports median, standard deviation and n in milliseconds.
Understand
Review in layers
Structure: one job per function, clear modules, no hidden globals. Correctness: tests with hand-worked answers and edge cases. Efficiency: count the hot loop and check the containers. Reporting: units, n, spread, honest axes and stated limits.
Look for hidden loops
x in some_list, list.pop(0), list.index(x) and string concatenation in a loop all hide a scan. Inside another loop they turn O(n) into O(n²). A set, a deque, a dict or "".join usually fixes it.
Numbers need context
A result without units, sample size, spread or method is not yet evidence. A good review asks: how was this computed, how uncertain is it, and does the chart show it fairly?
Explain it another way
Intuitive
Like a pit-stop check: tyres (structure), brakes (correctness), engine (efficiency), dashboard (reporting). Skip one and the car may still drive, until it doesn't.
Technical
Code review checklists catch more defects when they are specific: 'Is every membership test on a set or dict?', 'Does every function with a precondition check it?', 'Does every plot have labelled units?'.
Applied
Most engineering teams require at least one reviewer to approve a change before it is merged, and reviewers routinely check performance assumptions and charts as well as logic.
Worked example 1
Review this function. What's wrong, and what does the fixed version look like?
# BEFORE: works, but slow and its report misleads
def planner_report_before(times_ms):
seen = []
for t in times_ms:
if t not in seen: # hidden scan inside the loop: O(n^2)
seen.append(t)
avg = sum(times_ms) / len(times_ms) # crashes on an empty list
return "Planner is fast: " + str(int(avg)) # no unit, no spread, no n
# AFTER
import statistics as st
def planner_report(times_ms):
"""Summarise planning times in ms. Raises ValueError if there are none."""
if not times_ms:
raise ValueError("no timings to report")
distinct = len(set(times_ms)) # O(n) on average
spread = st.stdev(times_ms) if len(times_ms) > 1 else 0.0
return (f"median {st.median(times_ms):.1f} ms, s.d. {spread:.1f} ms, "
f"n = {len(times_ms)} runs ({distinct} distinct values)")
print(planner_report_before([12.0, 15.5, 12.0, 14.1]))
print(planner_report([12.0, 15.5, 12.0, 14.1]))
# Planner is fast: 13
# median 13.1 ms, s.d. 1.7 ms, n = 4 runs (3 distinct values)Common mix-ups
If the tests pass, the code is finished.
✓ It's correct for those tests. Review structure, efficiency and reporting too.Efficiency only matters for huge programs.
✓ A single hidden O(n²) line can make a small planner unusable on a realistic map.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Term assessment. Hand in your finished term project (planner package, tests, measurements, two plots, interpretation) together with a one-page review of a classmate's project (or the worked example) under the four headings. Assessed with the term rubric: correctness, software structure, efficiency analysis, visual communication.
Reflect
Which idea from this term will change how you write code next term, and why?
Write your answer on paper or in your own notes. Lite never stores what you write.