What Makes an Algorithm Good?

Week 1, Monday

January 5, 2026

Welcome to DSCI 221

Where to Start?

Canvas: canvas.ubc.ca/courses/182082

Course Website: ubc-cs.github.io/dsci221

Piazza: piazza.com/ubc.ca/winterterm22025/dsci221

Term Structure

Week Sunday M T W Lab HW/PA Examlet
1 1/4/2026 🎉 📺 🎉
2 1/11/2026 🎉 📺 🎉 🪄
3 1/18/2026 🎉 📺 🎉 🪄 HW1
4 1/25/2026 🎉 📺 🎉 🪄 🤩
5 2/1/2026 🎉 📺 🎉 🪄 PA1
6 2/8/2026 🎉 📺 🎉 🪄 HW2 🤩
7 2/15/2026      
8 2/22/2026 🎉 📺 🎉 🪄
9 3/1/2026 🎉 📺 🎉 🪄 PA2 🤩
10 3/8/2026 🎉 📺 🎉 🪄
11 3/15/2026 🎉 📺 🎉 🪄 🤩
12 3/22/2026 🎉 📺 🎉 🪄 PA3
13 3/29/2026 🎉 📺 🎉 🪄 🤩
14 4/5/2026   📺 🎉 HW3

Where’s Scott?

Taylor Swift’s Eras Tour, Nashville, TN

Which closet?

What’s this course about?

Course Goals

  • Become familiar with fundamental data structures and algorithms
    • Learn when to use them
  • Improve your ability to solve problems abstractly
    • Data structures and algorithms are the building blocks
  • Improve your ability to analyze algorithms
    • Prove correctness
    • Gauge, compare, and improve time and space complexity
  • Develop Python fluency for implementing solutions

Algorithm Analysis

What does it mean to analyze an algorithm?

Correctness

  • What does it mean for an algorithm to be correct?

 

  • If an algorithm is not correct, is its value 0?

Efficiency

Once we know it’s correct…

  • How long does it take?
  • How much memory does it use?

Shazam! demo

  • 3 seconds of audio

  • 100 million songs

  • less than 1 second

Shazam!

  • Shazam’s database: ~100 million songs
  • Your sample: 3 seconds of noisy audio
  • Checking one song: ~0.001 seconds

How long to check all songs?

An Algorithmic Approach

0 1 2 3 4 5 6 7 99,999,999
🎵 🎵 🎵 🎵 🎵 🎵 🎵 🎵 🎵
  • Is this correct?

  • How long does it take to run?

What factors might determine the running time?

Work with your neighbor: What factors affect how long find_song_naive takes?

Discussion results…

Machine speed

A faster computer runs the same code faster.

Location of song

At the front? Quick!

At the end? Slow.

Not there at all? Slowest.

Size of database

100 songs vs 100 million songs

We want to characterize the algorithm, not the machine or our luck.

The Scale Issue

Suppose our code requires ~0.001 second per song.

n = 100

100 × 0.001 = 0.1 sec

n = 100,000,000

100M × 0.001 = 27.8 hours

How does Shazam actually work?

shazam cluster_fingerprint Audio Fingerprinting audio 3 sec audio spec Spectrogram audio->spec land Landmarks spec->land hash Hash land->hash table Hash Table Lookup hash->table result Song Found! table->result

Constant vs. Linear

Database size Linear search Hash lookup
1,000 1 sec 0.001 sec
1,000,000 1000 sec 0.001 sec
100,000,000 27 hours 0.001 sec

Speed matters in surprising places

It’s not just Shazam!

YouTube

800 million videos

Every search: < 0.5 sec

Linear search would take hours

Genomics

Human genome: 3 billion base pairs

Finding a gene sequence

Naive: days → Real tools: seconds

Pandemic response

330 million people

Contact tracing within 2 connections

Relationships grow exponentially

As data grows, bad algorithms become impossible.

This Course

Data structures are clever ways to organize data so that algorithms can access it quickly.

What’s Next

This Week

Day Topic
Tuesday Counting steps, discovering patterns
Wednesday The hierarchy: O(1) to O(2ⁿ)

Questions?