Programming, problem solving, and algorithms

CPSC 203, 2025 W1

September 9, 2025

Announcements

Learning outcomes

  1. We connect the idea of “elegance” to common items and to software design!

  2. The time it takes to solve a problem is one way of measuring the size of a problem. That time can often be described by simple mathematical function.

Software design

Elegance

Find 2 images, one which exemplifies your definition of elegance, and another, of the same type of subject, which decidedly does not.

  1. Navigate to the Elegance Gallery: https://tinyurl.com/elegancegallery

  2. Claim an available slide by entering a title.

  3. Upload your images, and then you’re done!

  4. I will move slides to the COMPLETED section of the gallery.

10:00

Elegance: examples

Scissors

A set of scissors.

A pair of scissors with a single merged handle instead of two making it impossible to open and close blades.

A variety of scissors in different colours.

Your turn: Elegance—definition

Gallery: https://tinyurl.com/elegancegallery

After looking at the images in the gallery, reflect and write a short definition of the word elegance:

https://forms.gle/GL3yNZn7i7DT5qxW9

05:00

Elegance and computing

How does this apply to the way we solve problems in computing?

Ingenuity:



Simplicity:

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

Handcraft

Handcraft

A quilt in different colours—green and pink—and patterns—paisley and flowers.

A white doily with a spiral pattern on a wooden surface.

A pen made from pinecone.

A vibrant woven textile with intricate geometric patterns in various colours the main being red, displayed against a mossy wooden background.

A violin made from intricately quilled green paper with a bow.

A bicycle covered in crocheted yarn in various colours.

Knitting

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

Knitting pattern instructions for a Sherbet Stripes dishcloth with an image of the finished texture.

Knitting: examples

A knitted dishcloth with diagonal stripes in orange, green, yellow, and teal.

A teal knitted dishcloth with a lace pattern of diagonal eyelets.

A green knitted dishcloth featuring a textured dragon design.

A purple knitted dishcloth featuring a diamond lace pattern.

A teal knitted dishcloth featuring a raised power-up design from the video game Metroid.

A blue knitted dishcloth featuring a repeating heart pattern.

Quantifying the Task

A teal knitted dishcloth with a lace pattern of diagonal eyelets.

  1. If we describe one dimension of a square rag by \(n\), how much work is done by the knitter? ____________
  2. If we have enough yarn for 36,000,000 stitches, what is the largest rag we could make? ____________
  3. If each stitch takes a second, what is the largest rag we could make in one evening? ____________
  4. If it takes an evening to make a \(40 \times 40\) rag, how long will it take to make an \(80 \times 80\) rag? ____________
  5. If it takes time \(t\) to make an \(n\) by \(n\) rag, how long will it take to make a \(3n \times 3n\) rag? ____________

General idea: quantify the size of the problem (\(n\)) and consider the cost of our task as that size increases.

05:00

Quantifying the Task

If we are solving a problem ____________ for a given input, 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\).

A pixelated knitting pattern.

Discussion:

Handcraft and Code

Knitting model:

  • Side length is \(n\)

  • One stitch is a unit of work

  • \(n\) rows, \(n\) stitches per row

  • Total work is \(n^2\)

Quantifying the Task

Suppose we can knit 1012 stitches per second…

10 100 1000 10,000 1012
\(n\) 10-11s 10-10 s 10-9 s 10-8 s 1 s
\(n \log n\) 10-11 s 10-9 s 10-8 s 10-7 s 40 s
\(n^2\) 10-10 s 10-8 s 10-6 s 10-4 s 1012 s
\(n^3\) 10-9 s 10-6 s 10-3 s 1 s 1024 s
\(2^n\) 10-9 s 1018 s 10289 s

The amount of computation we do inside our algorithm actually matters!

Words and Ideas

  • Elegance

  • Growth of simple functions over time

  • Representing complexity of a problem using time

  • Running time of a Python function