CPSC 221 Basic Algorithms and Data Structures January
CPSC 221 Basic Algorithms and Data Structures January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 1
Course staff • Instructors – Cinda Heeren – will@cs. ubc. ca – Will Evans – cheeren@cs. ubc. ca – Geoffrey Tien – gctien@cs. ubc. ca ← that's me! – Geoff's office hours: Wednesday + Friday, 15: 00 – 16: 30, ICCS 245 January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 2
Administration Everything is on the course website! • https: //www. ugrad. cs. ubc. ca/~cs 221/ – – – – Staff – Instructors, TAs, course coordinator Communications + Piazza Lab activities Homeworks (HW) Programming assignments (PA) Exams Grading policies Academic integrity • https: //piazza. com/ubc. ca/winterterm 22018/cpsc 221 January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 3
Today's announcements • HW 1 available soon, to be due Jan. 11, 23: 59 • Lab sections are optional this week – TAs will give a quick introduction to command-line and machine setup (first half of lab 1) – Regular lab activities begin next week January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 4
Thinking about data structures and algorithms • How can you find a particular friend in this crowd? – think about the process, and what kinds of equipment you might (or might not) use January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 5
Data structures and algorithms • Hopefully we got a variety of solutions for the problem of finding a specific person in a concert – Each solution can be described in detailed sequence of steps – algorithm! – Each solution depended on the existence of certain hardware or organization of the collection – data structure! • Each solution (presumably) produces the same solution, i. e. locates the specified person – But they may all take different amounts of time or some other processing overhead – How can we have a consistent way to compare different solutions? January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 6
Data organization • I'm looking for (something specific). In which closet is it easier to find? January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 7
Measuring and comparing algorithms • January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 8
Running times What do they look like? • January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 9
Analyzing algorithms int mystery(vector<int>& arr, int q) { for (int i = 0; i < arr. size(); i++) if (arr[i] == q) return i; return -1; } • What does it do? • How long does it take? – Best case, worst case, average case? January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 10
Analyzing algorithms int mystery(vector<int>& arr, int) { for (int i = 0; i < arr. size(); i++) if (arr[i] == q) return i; return -1; } • January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 11
Asymptotic notation • We want to compare the "overall" runtime (or memory usage, etc. ) of our function against a familiar, simple function Time Input size January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 12
O-notation, visually • We want comparison to be valid for all sufficiently large inputs, but we are willing to ignore behaviour on small examples. Scale up the simple function if necessary Time Input size January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 13
Other asymptotic definitions • January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 14
Choosing the type of bound int mystery(vector<int> arr, int query) { for (int i = 0; i < arr. size(); i++) if (arr[i] == q) return i; return -1; } • January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 15
Readings for this lesson • Epp – Chapter 11. 2 (asymptotic notation) • Next class – analysis, continued January 02, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 16
- Slides: 16