CPSC 221

Introduction to Data Structures and Algorithms

Introductions

Us:

  • Cinda Heeren (Sec 101/102): cheeren@cs.ubc.ca · OH Tuesday 10:30–11:30 AM in ICCS 233
  • Nathan Harms (Sec 102): nharms@cs.ubc.ca · OH Monday 4:00–5:00 PM in ICCS X465
  • Course Coordinator: Anca Barbu — cpsc221-admin@cs.ubc.ca

TAs:

All you need to know is at…

https://ubc-cs.github.io/cpsc221/

Info on:

  • Staff
  • Communications
  • Lab sections
  • PAs
  • Exams
  • Marking
  • Academic Integrity
  • PAs — Due Mon after 2wk
  • HWs — Due Mon after 1wk
  • Labs — once a week, av Sun-Sun
  • Exams — 50min in ORCA
  • Class Meetings in FSC 1005
    • 101: MWF 2p,
    • 102: MWF 3p.

https://canvas.ubc.ca/courses/190808

Term Schedule

Week Mon M W F HW/PA Lab EX
1 Sep 7   🎉 🎉      
2 Sep 14 🎉 🎉 📹   🪄  
3 Sep 21 🎉 🎉 📹 🏎️ 🪄 🤩
4 Sep 28 🎉   📹   🪄 🤩
5 Oct 5 🎉 🎉 📹 🚀 🪄 🤩
6 Oct 12   📹 📹      
7 Oct 19 🎉 🎉 📹 🏎️ 🪄 🤩
8 Oct 26 🎉 🎉 📹   🪄 🤩
9 Nov 2 🎉 🎉 📹 🚀 🪄 🤩
10 Nov 9     📹      
11 Nov 16 🎉 🎉 📹   🪄 🤩
12 Nov 23 🎉 🎉 📹 🚀 🪄 🤩
13 Nov 30 🎉 🎉 📹 🏎️ 🪄 🤩
14 Dec 7 🎉          

Legend: 🎉 in-person lecture   📹 async video   🪄 lab   🤩 examlet   🏎️ HW due   🚀 PA due     off / nothing due

Grading

Component Weight
🎉 Class meetings attendance not required 0%
🪄 Labs best 8 of 10 × 1% 8%
🏎️ Homework 3 × 2% 6%
🚀 Programming assignments 3 × 2% 6%
🤩 Examlets 9 × 6% 54%
🏆 Final exam cumulative 26%
100%

80% of your grade is written under invigilation.

Today’s announcements

  1. Labs start next week
  2. Class meets in person this Friday

Today’s Plan:

  1. intro to algorithm analysis — code!

What’s this course about?

Where’s Meghan?

Observations:

Which closet…

↔︎

Course Goals

  • Become familiar with some of the fundamental data structures and algorithms in computer science
    • 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
  • Become modestly skilled with C++ and UNIX

Measuring the value of algorithms

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


  • Use different metrics — time, space most common
  • Express running times as a (positive) function:


  • Form of function depends on structure of the algorithm…

Running times

Suppose a computer executes \(10^{12}\) operations per sec.

operations n=10 n=100 n=1000 n=10,000 n=\(10^{12}\)
\(n\) \(10^{-11}\) s \(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 \(10^{12}\) s
\(n^3\) \(10^{-9}\) s \(10^{-6}\) s \(10^{-3}\) s 1 s \(10^{24}\) s
\(2^n\) \(10^{-9}\) s \(10^{18}\) s \(10^{289}\) s

Algorithmic Analysis — example 1

int ____________ (vector<int> arr, int q) {
    for (int i = 0; i < arr.size(); i++)
        if (arr[i] == q)
            return i;
    return -1;
}

What questions do you have about the code?