CPSC 203, 2026 W1
September 15, 2026
Results of course survey.
Updates to CPSC 203 course website.
Monitor (and post to) Piazza.
POTW is available on PrairieLearn.
Enroll in CPSC203 on PrairieTest.
define shopping_trip1(grocery_list: List[food_item])
-> pantry_list: List[food_item]:
# List of food in the pantry so far.
pantry_list = []
for item_on_grocery_list in grocery_list:
# Take paper with single item to the store.
item_at_store = go_to_store(item_on_grocery_list)
# Get the item from the shelf.
item_in_cart = pick_at_store(item_at_store)
# Bring the item home.
item_at_home = return_from_store(item_in_cart)
# Put the item away.
pantry_list.append(put_in_pantry(item_at_home))
return pantry_listI am being sloppy here by assuming that the helper functions can accept (and will return) either a single item or a list of items
If we have \(n\) items in our list, how long does this procedure take?
define shopping_trip2(grocery_list: List[food_item])
-> pantry_list: List[food_item]:
# Take piece of paper with list to the store.
grocery_list_at_store = go_to_store(grocery_list)
# Get all items on the list into the cart.
cart_list = []
for item_at_store in grocery_list_at_store:
cart_list.append(pick_at_store(item_at_store))
# Bring the items home.
grocery_bags_at_home = return_from_store(cart_list)
# Put the items away.
pantry_list = []
for item_at_home in grocery_bags_at_home:
pantry_list.append(put_in_pantry(item_at_home))
return pantry_listIf we have \(n\) items in our list, how long does this procedure take?






The language used to communicate patterns uses exactly the same fundamental constructs as Python!!!








General idea: quantify the size of the problem (\(n\)) and consider the cost of our task as that size increases.
If we are solving a problem / writing an algorithm for an input of arbitrary size, we can parameterize the running time of the solution by the size of the input.
We usually denote this input size using the variable \(n\).
![]()
Simplicity is the ultimate sophistication. It takes a lot of hard work to make something simple, to truly understand the underlying challenges and come up with elegant solutions. […] It’s not just minimalism or the absence of clutter. It involves digging through the depth of complexity. To be truly simple, you have to go really deep. […] You have to understand the essence of a product in order to be able to get rid of the parts that are not essential.
— Steve Jobs
Knitting model:
Side length is \(n\)
One stitch is a unit of work
\(n\) rows, \(n\) stitches per row
Total work is \(n^2\)
Suppose we can knit 1 (= 100) stitches per second….
The degree (in n) makes a very big difference!
| time \ n | 10 | 100 | 1000 |
|---|---|---|---|
| log n | ~3 s | ~6½ s | ~10 s |
| n | 10 s | 102 s ~ 1½ min | 103 s ~ 16½ min |
| n log n | 3(10) s ~ ½ min | 6(102) s ~ 10 min | 104 s ~ 2½ hours |
| n2 | 100 s ~ 1½ min | 104 s ~ 2½ hours | 106 s ~ 11½ days |
| n3 | 1000 s ~ 16½ min | 106 s ~ 11½ days | 109 s ~ 31½ years |
| 2n | 1024 s ~ 17 min | ~1030 s | ~10301 s |
Notes: “log” is base 2, and the age of the universe: ~1018 s
But computers are much faster. Suppose we can “knit” 1012 stitches / s
| time \ n | 10 | 100 | 1000 | 106 | 1012 |
|---|---|---|---|---|---|
| log n | ~3(10-12) s | ~6½(10-12) s | ~10(10-12) s | ~20(10-12) s | ~40(10-12) s |
| n | 10-11 s | 10-10 s | 10-9 s | 10-6 s | 1 s |
| n log n | 3(10-11) s | 6(10-10) s | 10-8 s | ~20(10-6) s | ~40 s |
| n2 | 10-10 s | 10-8 s | 10-6 s | 1 s | 1012 s |
| n3 | 10-9 s | 10-6 s | 10-3 s | 106 s | 1024 s |
| 2n | ~10-9 s | ~1018 s | ~10289 s |
Notes: proteins fold in ~10-6 s and the age of the universe: ~1018 s
So the amount of computation we do inside our algorithm actually matters as our data increases.