CPSC 221 Basic Algorithms and Data Structures January
CPSC 221 Basic Algorithms and Data Structures January 06, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 1
Course staff • Instructors – Cinda Heeren – cheeren@cs. ubc. ca – Andy Roth – aroth@cs. ubc. ca – Geoffrey Tien – gctien@cs. ubc. ca ← that's me! – Geoff's office hours (ICCS 245): Thursday, 14: 00 – 15: 30 – Friday, 15: 30 – 17: 00 January 06, 2020 Cinda Heeren / Andy Roth / 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 22019/cpsc 221 January 06, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 3
Today's announcements • HW 1 available soon • Lab sections are beginning/already begun today! • Midterms: – Wednesday, February 05 evening (time and location TBA) – Wednesday, March 04 evening (time and location TBA) – If you have a conflict, you MUST e-mail our course coordinator at least 2 weeks in advance of the exam date – cpsc 221 -admin@cs. ubc. ca January 06, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 4
Thinking about data structures and algorithms Contact Winter Music Festival 2019 • 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 06, 2020 Cinda Heeren / Andy Roth / 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 06, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 6
Data organization • I'm looking for (something specific). In which closet is it easier to find? January 06, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 7
Measuring and comparing algorithms • January 06, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 8
Running times What do they look like? • January 06, 2020 Cinda Heeren / Andy Roth / 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; } arr 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 32 11 73 21 29 86 81 92 57 61 64 15 79 44 7 45 • What does it do? • How long does it take? – Best case, worst case, average case? January 06, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 10
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; } arr 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 32 11 73 21 29 86 81 92 57 61 64 15 79 44 7 45 • January 06, 2020 Cinda Heeren / Andy Roth / 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 06, 2020 Cinda Heeren / Andy Roth / 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 January 06, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien Input size 13
Other asymptotic definitions • January 06, 2020 Cinda Heeren / Andy Roth / 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 06, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 15
Readings for this lesson • Carrano & Henry – Chapter 10 (algorithmic efficiency) • Epp – Chapter 11. 2 – 11. 3 (asymptotic notation) • Next class – analysis, continued January 06, 2020 Cinda Heeren / Andy Roth / Geoffrey Tien 16
- Slides: 16