COMP Data Structures

Similar documents
COMP Data Structures

COMP Analysis of Algorithms & Data Structures

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

VE281 Data Structures and Algorithms. Introduction and Asymptotic Algorithm Analysis

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

CPSC 2380 Data Structures and Algorithms

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

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

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

CSC2100-Data Structures

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

COMP Data Structures

CISC 3130 Data Structures Spring 2018

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

Data Structures and Algorithms

CS 240 Fall 2015 Section 004. Alvin Chao, Professor

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

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

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

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

CPSC 331 Term Test #2 March 26, 2007

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 25: Review and Open Problems

ECE250: Algorithms and Data Structures Midterm Review

Data Structures Lecture 8

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

Algorithms in Systems Engineering IE172. Midterm Review. Dr. Ted Ralphs

AP Computer Science AB

Algorithms and Data Structures Spring 2008

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

Advanced Algorithms and Data Structures

Part 1: Written Questions (60 marks):

SAMPLE. COS 161 Algorithms in Programming. Prof. Briggs Fall 2017

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

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

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

AP Computer Science 4325

COLLEGE OF THE DESERT

KOMAR UNIVERSITY OF SCIENCE AND TECHNOLOGY (KUST)

CS 241 Data Organization. August 21, 2018

Unit 10: Data Structures CS 101, Fall 2018

CISC 3130 Data Structures Fall 2018

3D Graphics Programming Mira Costa High School - Class Syllabus,

Data Structures and Algorithms

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

Advanced Algorithms and Data Structures

Announcements. 1. Forms to return today after class:

CS302 Data Structures using C++

CS 4800: Algorithms & Data. Lecture 1 January 10, 2017

CS 241 Data Organization using C

CS 483. Jana Kosecka CS Dept Eng. Building

CPSC 221: Algorithms and Data Structures Lecture #0: Introduction. Come up and say hello! Fibonacci. Fibonacci. Fibonacci. Fibonacci. (Welcome!

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

Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types

COMP Analysis of Algorithms & Data Structures

Introduction to Programming System Design CSCI 455x (4 Units)

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

Computer Programming II C++ (830)

COMP250: Introduction to algorithms The set-intersection problem

1. Attempt any three of the following: 15

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

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

CS 216 Fall 2007 Final Exam Page 1 of 10 Name: ID:

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

Introduction to Information Technology ITP 101x (4 Units)

Computer Science II Data Structures

Course Review. Cpt S 223 Fall 2009

Welcome to CSE 326: Data Structures & Algorithms

Introduction to Data Structures

CSC116: Introduction to Computing - Java

Computer Science 210: Data Structures

CS301 - Data Structures Glossary By

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

61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013

Implementing Hash and AVL

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

Al al-bayt University Prince Hussein Bin Abdullah College for Information Technology Computer Science Department

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

Organisation. Assessment

CSC 111 Introduction to Computer Science (Section C)

CS 445: Data Structures Final Examination: Study Guide

Draw a diagram of an empty circular queue and describe it to the reader.

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu

AE Computer Programming for Aerospace Engineers

Data Structures. Lecture 1: Introduction CSC212. Instructor: George Wolberg Department of Computer Science City College of New York

CSC116: Introduction to Computing - Java

San José State University Computer Science Department CS49J, Section 3, Programming in Java, Fall 2015

ECE250: Algorithms and Data Structures Final Review Course

07 B: Sorting II. CS1102S: Data Structures and Algorithms. Martin Henz. March 5, Generated on Friday 5 th March, 2010, 08:31

About this exam review

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

Final Examination CSE 100 UCSD (Practice)

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

CS61BL. Lecture 5: Graphs Sorting

CSE 373: Introduction, ADTs, Design Decisions, Generics. Michael Lee Wednesday Jan 3, 2017

Algorithms and Data Structures

Today. An Animated Introduction to Programming. Prerequisites. Computer programming

COT 5407: Introduction to Algorithms. Giri Narasimhan. ECS 254A; Phone: x3748

CPSC 213. Introduction to Computer Systems. About the Course. Course Policies. Reading. Introduction. Unit 0

MPATE-GE 2618: C Programming for Music Technology. Syllabus

Transcription:

COMP 2140 - Data Structures Shahin Kamali Topic 1 - Introductions University of Manitoba Based on notes by S. Durocher. COMP 2140 - Data Structures 1 / 35

Introduction COMP 2140 - Data Structures 1 / 35

In a Glance... Data structures are building blocks for designing algorithms practical and diverse fun (really!) Let s learn & play data structures & algorithms and enjoy COMP 2140 - Data Structures 2 / 35

Instructor Shahin Kamali B.Sc. in Computer Science (2002-2006) University of Tehran (Iran) M.Sc. in Computer Science (2006-2008) Concordia University (Canada) PhD in Computer Science (2008-2014) University of Waterloo (Canada) Visiting Researcher (2014-2015) LIAFA, Paris (France) Postdoctoral Fellow, Associate (2015-2017) MIT (USA) Assistant professor (since 2017) University of Manitoba COMP 2140 - Data Structures 3 / 35

Formalities COMP 2140 - Data Structures 3 / 35

Logistics Lecture: Mondays, Wednesdays, and Fridays, 9:30-10:20am EITC E2 Rm: 110 (Jan. 07, 2018 - Apr. 09, 2018) Webpage: http://www.cs.umanitoba.ca/ kamalis/winter19/comp2140.html Piazza: piazza.com/umanitoba.ca/winter2019/comp2140 Office hours: 1:00 to 2:00 pm on Mondays, 10:30 to 11:30 am Tuesdays, Location: E2 586 or by appointment You can post your questions (if you prefer anonymously) on Piazza so that all your classmates see the solution You should have received an email with respect to Piazza COMP 2140 - Data Structures 4 / 35

Textbook All material (including the slides) will be posted online Slides are the main source for assignments and exams. The following free book can be used as a reference: Open Data Structures (in Java), Pat Morin COMP 2140 - Data Structures 5 / 35

Programming For programming, you use Java You can use any operating system Post your questions on Piazza Students who actively respond to questions on Piazza will get bonus marks. Help center: located in E2-422A Email precise and specific questions to the instructor COMP 2140 - Data Structures 6 / 35

Grading There will be: Five assignments (20 percent of the final mark) Two quizzes (10 percent) Labs (10 percent) A midterm exam (20 percent) A final exam (40 percent) Theorem The focus of this course is on learning, practising, and discovering. Corollary Having fun in the process is important. COMP 2140 - Data Structures 7 / 35

Grading (cntd.) Five assignments: 20 percent of the final mark 5 to 10 percent extra for bonus questions. submit only pdf files Quizzes, Midterm & Final exams: Labs: respectively 10, 20 & 40 percent of the final mark. there will be extra for bonus questions in midterm and final. all are closed-book. sample exams will be provided for practice for the final. 10 percent of the final mark There will be a lab roughly in each two weeks. Two motivated graduate students will help you. You will implement data structures and algorithms reviewed in the class using Java. COMP 2140 - Data Structures 8 / 35

Important Dates (tentative) More information on ROASS. COMP 2140 - Data Structures 9 / 35

Prerequisites What I have learned from previous courses? Object Oriented Programming Java syntax Basic sorting (bubble-sort, insertion-sort, selection-sort) Recursion (base-case, recursive-case) Basic data structures (arrays, linked-lists) Basic analysis of algorithms (e.g., big O notation) COMP 2140 - Data Structures 10 / 35

Introduction to Algorithms & Data Structures COMP 2140 - Data Structures 10 / 35

Algorithms What is an algorithm? Definition An algorithm is a computational procedure formed by a sequence of instructions (steps) to solve a problem The problem has an input and requires an output Solving the problem requires the algorithm to terminate. COMP 2140 - Data Structures 11 / 35

Angle bisection Example input: an angle defined by three points aob. output: a point c such that aoc = boc. Algorithms: 1 Draw a circle C centred at o. 2 Label the intersection of C and ao as a. 3 Label the intersection of C and bo as b. 4 Draw circles Ca and Cb centred at a and b that pass through o. 5 Label the intersection of Ca and Cb as c. 6 Return c. COMP 2140 - Data Structures 12 / 35

Algorithm definition Why that was an algorithm for angle bisection? It has an input (the angle) and an output (the point C) It terminates (there is no loop in this algorithm) It is correct: one can prove that the reported point is always on the bisection. This step often require theoretical analysis COMP 2140 - Data Structures 13 / 35

Algorithm Description How to describe an algorithm? Example input: a set of integers output: the largest number in the set An algorithm can be described in a number of ways: English prose pseudo-code actual source code in a programming language (e.g., Java or C++) pseudo-code assembler language machine language (executable) COMP 2140 - Data Structures 14 / 35

Finding the Maximum: English Prose Example input: a set of integers output: the largest number in the set Initialize a variable maxmark to the value of the first element in the list. For each subsequent element in the list, if that element is larger than maxmark, then replace maxmark with the value of that element. After examining all elements, return maxmark. COMP 2140 - Data Structures 15 / 35

Finding the Maximum: Pseudocode A more precise description of an algorithm (than English prose) which is closer to an actual implementation. Example input: a set of integers markslist output: the largest number in the set COMP 2140 - Data Structures 16 / 35

Finding the Maximum: Java Code The actual source code using a programming language. Example input: a set of integers markslist output: the largest number in the set COMP 2140 - Data Structures 17 / 35

Finding the Maximum: Assembly Each CPU has a low-level set of instructions to perform basic operations on data stored in registers and in memory. Example input: a set of integers markslist output: the largest number in the set COMP 2140 - Data Structures 18 / 35

Finding the Maximum: Machine language A binary sequence that is specific to the CPU for which it was compiled. Example input: a set of integers markslist output: the largest number in the set COMP 2140 - Data Structures 19 / 35

Types of Problems We Will Solve Using Algorithms Example input: a list of integers/real-values output: the same list in sorted order Example input: a database of records and a query key output: determine whether the key exists is the database Example input: the address of two houses in Winnipeg output: the shortest route between these two houses COMP 2140 - Data Structures 20 / 35

Types of Algorithms We Will Study We will examine algorithms for: sorting a list inserting/deleting elements into/from a database querying a database merging databases scheduling prioritized events updating the priority of an event finding shortest routes We will consider multiple algorithms for solving each of these problems, and compare these various algorithms against each other. COMP 2140 - Data Structures 21 / 35

Comparing Algorithms Alice and Bob implemented two algorithms for the same problem X. Alice: When I input an array of 200 integers, my algorithm takes 910 milliseconds on a 3.3 GHz quadcore Intel i7 with 8Gb of RAM running Windows 7. It s only 80 lines of C code. I optimized the compilation but the executable doesn t run on anyone else s computer except mine. Bob: When I input an array of 2000 floating point numbers, my algorithm 12.59 seconds on a 2.8 GHz AMD Athlon with 512Mb of RAM running Linux. It s only 122 lines of Java code. I used the default compiler settings and it can be interpreted by any version of Java 2.0 or higher. Note they used different inputs, different hardware, different operating systems, different programming language, and different compiler optimization. Which algorithm is better? COMP 2140 - Data Structures 22 / 35

Comparing Algorithms If two algorithms A and B both solve problem P, what makes one algorithm better than the other? possible criteria: runtime taken amount of memory storage required number of data movements amount of network traffic generated time required to implement ease of debugging, modifying, and updating cost of hiring specialized programmers (U of M graduates) Runtime and memory requirements will be of particular interest in this course. We will discuss tools for comparing algorithms (e.g., big Oh notation). COMP 2140 - Data Structures 23 / 35

Determining the Size of the Intersection Example input: a list of names of students taking COMP 2140 and a list of names of students taking MATH 1500 assumption: no two students have the same name output: the number of students taking both courses COMP 2140 - Data Structures 24 / 35

Determining the Size of the Intersection: solution I Compare every name from list A against every name from list B and count the number of matches. Assume list A is stored in an array of length n and list B is stored in an array of length m. access to arrays A or B: f (n, m) =? COMP 2140 - Data Structures 25 / 35

Determining the Size of the Intersection: solution II Merge the two lists into a single list, sort it, and count the number of adjacent values that match. access to arrays A or B: g(n, m) =? COMP 2140 - Data Structures 26 / 35

Determining the Size of the Intersection: comparison To compare algorithms we often care about larger inputs. Why? COMP 2140 - Data Structures 27 / 35

Determining the Size of the Intersection Other possible solutions: Solution 3 Sort array B. For each i = 0... n 1, search for A[i] in array B using binary search. Count the number of matches. access to arrays A or B (worst case):? Solution 4 Sort array A. Sort array B. Initialize i and j to 0. Check whether A[i] = B[j]; if so, add one to the number of matches, and increment i. If A[i] > B[j] then increment j. Otherwise, if A[i] < B[j] then increment i. Repeat until i = n or j = m. access to arrays A or B (worst case)? COMP 2140 - Data Structures 28 / 35

Comparing Algorithms Conclusion There are many ways - algorithms - to solve a given problem. To compare different algorithms, we often measure the time complexity. In doing so, we consider worst-case scenarios and assume large input sizes. A good implementation (programming language, compiler, good programming techniques, etc.) can make a code tens, possibly hundreds of times faster. A good design, that is a good algorithm/data-structure, can make a solution hundreds of thousands, possibly millions of times faster. COMP 2140 - Data Structures 29 / 35

Data Structures In order to access & manipulate data (e.g., a list of integers, a database of records, a map of the subway) we need a representation of these data that is stored in memory. Definition A data structure is a systematic way of organizing and accessing data. In COMP 2140, we analyze different data structures for storing various types of data. Depending on the intended application and the algorithms involved, different data structures msight be used to store the same data. COMP 2140 - Data Structures 30 / 35

Examples of Data Structures Some of the data structures we will discuss include: array linked list doubly-linked list binary search tree binary heap hash table adjacency list adjacency matrix COMP 2140 - Data Structures 31 / 35

Examples of Data Structures The following are graphical representations of data structures that store the integers 30, 61, 12, 23, 77, and 52. COMP 2140 - Data Structures 32 / 35

Abstract Data Type What is an Abstract Data Type (ADT) Definition An abstract data type is formed by I) a set of values (data items) and II) a set of operations allowed on these items Stack is an ADT. Data items can be anything and operations are push and pop An ADT is abstract way of looking at data (no implementation is prescribed) An ADT is the way data looks from the view point of user COMP 2140 - Data Structures 33 / 35

ADTs vs Data Structures ADTs: stacks, queues, priority queues, dictionaries Data structures array, linked-list, binary-search-tree, binary-heap hash-table-using-probing, hash-table-using-chaining, adjacency list, adjacency matrix, etc. COMP 2140 - Data Structures 34 / 35

Data Abstraction In designing algorithmic solutions, we often separate implementation from data and its operations Design Phase design algorithmic solution select corresponding ADTs analyze memory and running time requirements Implementation Phase plan and organize code using the object-oriented programming paradigm: classes, methods, and instance variables use good coding style testing COMP 2140 - Data Structures 35 / 35