COMP251: Algorithms and Data Structures. Jérôme Waldispühl School of Computer Science McGill University

Similar documents
COMP250: Introduction to Computer Science. Jérôme Waldispühl & Carlos Oliver Gonzalez School of Computer Science McGill University

AP Computer Science 4325

COMP Analysis of Algorithms & Data Structures

COMP250: Priority queue ADT, Heaps. Lecture 23 Jérôme Waldispühl School of Computer Science McGill University

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid. Fall 2018

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014

Course Review. Cpt S 223 Fall 2009

Course Review. Cpt S 223 Fall 2010

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

Priority Queues Heaps Heapsort

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

Course Review for Finals. Cpt S 223 Fall 2008

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Design and Analysis of Algorithms. Comp 271. Mordecai Golin. Department of Computer Science, HKUST

COMP Data Structures

CISC 3130 Data Structures Spring 2018

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

COMP Data Structures

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

INSTITUTE OF AERONAUTICAL ENGINEERING

CS 210 Algorithms and Data Structures College of Information Technology and Engineering Weisberg Division of Engineering and Computer Science

COMP 250 Fall Homework #4

CS2013 Course Syllabus Spring 2018 Lecture: Mon/Wed 2:00 P.M. 2:50 P.M. SH C259 Lab: Mon/Wed 2:50 P.M. 4:00 P.M. SH C259

VE281 Data Structures and Algorithms. Introduction and Asymptotic Algorithm Analysis

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

CSE 373 APRIL 17 TH TREE BALANCE AND AVL

Data structures. Priority queues, binary heaps. Dr. Alex Gerdes DIT961 - VT 2018

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

(2,4) Trees. 2/22/2006 (2,4) Trees 1

Advanced Algorithms and Data Structures

Implementing Hash and AVL

Algorithms and Data Structures Spring 2008

Course goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance

Lecture Summary CSC 263H. August 5, 2016

COMP251: Background. Jérôme Waldispühl School of Computer Science McGill University

COMP 250 Midterm #2 March 11 th 2013

CISC 3130 Data Structures Fall 2018

CS 240 Fall Mike Lam, Professor. Just-for-fun survey:

BOSTON UNIVERSITY Metropolitan College MET CS342 Data Structures with Java Dr. V.Shtern (Fall 2011) Course Syllabus

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015

Data Structures Question Bank Multiple Choice

CS2013 Course Syllabus Spring 2017 Lecture: Friday 8:00 A.M. 9:40 A.M. Lab: Friday 9:40 A.M. 12:00 Noon

COMP 250. Lecture 36 MISC. - beyond COMP final exam comments

COMP 2150 CS 2: Object-Oriented Programming and Data Structure Fall 2018 Dr. James Yu

Binary Trees, Binary Search Trees

Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis

Final Exam. EECS 2011 Prof. J. Elder - 1 -

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

CS301 - Data Structures Glossary By

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302

Virtual University of Pakistan

CS171 Final Practice Exam

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims

The questions will be short answer, similar to the problems you have done on the homework

CMSC 341 Priority Queues & Heaps. Based on slides from previous iterations of this course

Heaps. 2/13/2006 Heaps 1

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

Priority Queues Heaps Heapsort

Priority queue ADT Heaps. Lecture 21

Data Structures and Algorithms

Binary Search Trees Treesort

Suggested Study Strategy

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

Course Syllabus for CS3358 (Data Structures and Algorithms) by Lee S. Koh

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

Lecture 11: Multiway and (2,4) Trees. Courtesy to Goodrich, Tamassia and Olga Veksler

Algorithms and Data Structures

CS171 Final Practice Exam

Total No. of Questions :09] [Total No. of Pages : 02. II/IV B.Tech. DEGREE EXAMINATIONS, NOV/DEC First Semester CSE/IT DATA STRUCTURES USING C

CS 445: Data Structures Final Examination: Study Guide

Assignment Tutorial.

ECE250: Algorithms and Data Structures Final Review Course

Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix

Final Examination CSE 100 UCSD (Practice)

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Binary Trees

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

CSE 100 Advanced Data Structures

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

Welcome to CSL 201 Data Structures

CS/COE 1501 cs.pitt.edu/~bill/1501/ Introduction

CLO Assessment CLO1 Q1(10) CLO2 Q2 (10) CLO3 Q4 (10) CLO4 Q3a (4)

CS302 Data Structures using C++

CS583 Lecture 01. Jana Kosecka. some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes

3137 Data Structures and Algorithms in C++

CMSC 341 Lecture 14: Priority Queues, Heaps

Cpt S 223 Course Overview. Cpt S 223, Fall 2007 Copyright: Washington State University

CSE373: Data Structures & Algorithms Lecture 5: Dictionary ADTs; Binary Trees. Linda Shapiro Spring 2016

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

St. MARTIN s ENGINERING COLLEGE Dhulapally,Secunderabad

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY

Computer Science E-22 Practice Final Exam

17 February Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough.

Data Structures and Algorithms

Data Structures and Algorithms

Algorithms and Data Structures, or

Transcription:

COMP251: Algorithms and Data Structures Jérôme Waldispühl School of Computer Science McGill University

About Me Jérôme Waldispühl Associate Professor of Computer Science I am conducting research in Bioinformatics How to reach me? o Office hours (TBA) o By appointment (email me to schedule a meeting) o Email: cs251@cs.mcgill.ca (Note: This will be the only email address you should use and from which you can expect an answer)

Where to get announcements & updates? Official channel: Course web page: http://www.cs.mcgill.ca/~jeromew/comp251.html Other channels MyCourses In class!

Evaluation 40% for 5 assignments 10% for quizzes* 49% for the final exam 1% for agreeing and following course policy * The quizzes are optional. If the average grade of the quizzes is lower than your score at the final exam, the weight of the quizzes will be reported to the final (i.e. your final will count for 60% of your grade). Warning: There will be no modification of this scheme.

Schedule Classes start Today Classes end on November 28 (included). No midterm. Final exam: TBD

Organization Lecture are recorded and available for streaming but cannot be downloaded. Slides available on the course webpage. Overflow room is expected to close at end of Week 1. Check schedule online to find TA office hours. Programming questions have to be asked to TAs, but do not expect TAs to debug your code for you. We have tutorials (e.g. Sep 25). How to reach us? cs251@cs.mcgill.ca

Outline Sep 4-6: Background & Review Sep 11: Hash tables Sep 13-27: Tree ADT Sep 25: Tutorial Oct 2 nd : Intro to Algorithm design (Greedy algorithm) Oct 4-25: Graph algorithm Oct 30 - Nov 13: Algorithm design Nov 15-22: Algorithm analysis & randomized algorithms Nov 27-29: Review

What is different from COMP250? Algorithm design Proofs (correctness) Analysis of performance Requirement: Basic understanding of probabilities and discrete math (See co-requisites).

Textboooks [CLRS2009] Cormen, Leiserson, Rivest, & Stein, Introduction to Algorithms. (Available as E-book at the McGill library) [KT2006] Kleinberg & Tardos, Algorithm Design. Textbooks are recommended but not mandatory.

Assignments Only programming questions Programming Language: Java Read carefully the formatting guidelines. Strictly follow the formatting guidelines. Submit your answers electronically on MyCourse. Each file must be submitted separately. Do not zip your files! Re-submission accepted before the deadline. Discuss the assignment, but do not share/copy solutions. Write (in comments) the name of persons with whom you discussed/collaborated (including instructor and TA).

Answering programming questions Submit the Java source file (i.e. not class file) Separate MyCourses folder Ensure that your files compile on SOCS workstations (Note: Create an account if you do not already have one) Indent and comment your code! Use the template provided. Do not use custom libraries (unless specified). Follow the syntax of the command line provided in the question. Use the test input & output (Note: It does not guarantee that your program is 100% correct).

Tips We will provide test cases (i.e. input & output). Use them! BUT note that passing all tests does not guarantee that your program is 100% correct. We will use different ones to check that your program is correct. It is your responsibility to guarantee that your program: Compile on SOCS workstations Run with the proper syntax of the command line Produces an output that follows the guidelines Submit early. We will run the grader ~24h before the deadline. It will give you an opportunity to fix your assignment and resubmit before the deadline.

Policy Late assignments will receive a 20% penalty if they are returned within less than 24h after the end of the deadline. They will not be graded afterward. (Tip: Submit preliminary versions early) The only exceptions will be medical exceptions. You must provide a medical note (instructor & McGill). No plagiarism!

Next class Review of COMP 250 material Take online quiz (Practice only. not graded! Link available tomorrow on course website) Basic probability (expectation, indicator)

Binary numbers Definition Conversion decimal binary Addition Size of the representation

Recursions Definition (recursive case & base case) Binary search Fibonacci Merge Sort How to write a function describing the running time of a recursive algorithms. Estimate the number of recursive calls. Dividing original problem into roughly equal size subproblems usually gives better running times.

Running time and big-oh Running time: o Counting primitive operations o Dealing with loops: S n i=1 i = n (n+1)/2 is O(n 2 ) o Worst-case vs average-case vs best-case Big-Oh notation: o o Mathematical definition Big-Oh is relevant only for large inputs. For small inputs, big-oh may be irrelevant (remember integer multiplications) Big-Theta, Big-Omega Unless mentioned otherwise, big-oh running time is for worst-case. You need to know and understand the big-oh running time of all algorithms seen in class and in homeworks.

Data Structures Array running time for insert, delete, find... Single-linked list Better than arrays: Easier to insert and delete No need to know size in advance Worse than arrays: finding the n-th element is slow (so binarysearch is hard) Require more memory (for the "next" member) Doubly-linked list Allow to move backward Makes deleting elements easier Stacks and queues You should understand all applications we saw

ADT (Abstract Data Structure) What it is? Description of the interface of a data structure. It specifies: What type of data can be stored What kind of operations can be performed Hides the details of implementation Why it is important? Simplifies the way we think of large programs

Trees treenode representation Vocabulary: node, leaf, root, parent, sibling, descendants, ancestors, subtree rooted at x, internal and external nodes, ordered, binary, proper binary Depth and height Definition How to compute it. Tree traversal Pre-order, In-order, Post-order

Dictionary ADTs Stores pairs (key, info) Operations: find(key), insert(key, info), remove(key) Cases where array implementation is bad (with complexity) Cases where linked-list implementation is bad (with complexity)

Dictionary ADTs with Binary Search trees (BST) Property: for any node x, keys in the left subtree of x have keys smaller or equal to key(x) and keys in the right subtree of x have keys larger or equal to key(x) Algorithm to find a key and its running time O(h) = O(log n) if the tree is balanced. Inserting a new key. Running time O(h). Sequence of insertion that can lead to bad running times. Removing a key. You need to be able to execute these algorithms by hand on examples.

Dictionary ADTs with Hash Tables Implements a dictionary Idea: map keys to buckets Each bucket is itself a dictionary Hash functions: Goal: minimize collisions Easy to compute Best case: keys are distributed uniformly among the buckets. Each bucket contains few keys Worst case: All keys end-up in the same bucket

Priority queues Heap property: key(x) is smaller or equal to the keys of children of x. All h-1 first levels are full, and in the last level, nodes are packed to the left Operations: findmin(). Algorithm. O(1) insert(key). Bubbling-up. O(log n) removemin(). Bubbling-down. O(log n) Array representation of heaps HeapSort insert keys one by one removemin() one by one

Graphs All the terminology Data structures for representing graphs: Adjacency-list Adjacency-matrix Running time of basic operations with each data structure Graph traversal Depth-first search Recursive Iterative using a stack Breadth-first search Iterative using a queue IMPORTANT: Applications of DFS and BFS