Trevor Brown trevor.brown@uwaterloo.ca CS 341: Algorithms Trevor Brown trevor.brown@uwaterloo.ca.

Slides:



Advertisements
Similar presentations
Algorithm Design Techniques
Advertisements

MATH 224 – Discrete Mathematics
A simple example finding the maximum of a set S of n numbers.
Design and Analysis of Algorithms Maria-Florina (Nina) Balcan Lecture 1, Jan. 14 th 2011.
Lecture 8 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Jan Welcome to the Course of Advanced Algorithm Design (ACS-7101/3)
CS 46101–600/CS Design and Analysis of Algorithms Dr. Angela Guercio Spring 2010.
CSIS-385: Analysis of Algorithms Dr. Eric Breimer.
CS333/ Topic 11 CS333 - Introduction CS333 - Introduction General information Goals.
CSIS-385: Analysis of Algorithms Dr. Eric Breimer.
Unit 1. Sorting and Divide and Conquer. Lecture 1 Introduction to Algorithm and Sorting.
Instructor: Dr. Sahar Shabanah Fall Lectures ST, 9:30 pm-11:00 pm Text book: M. T. Goodrich and R. Tamassia, “Data Structures and Algorithms in.
Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.
1.1 Chapter 1: Introduction What is the course all about? Problems, instances and algorithms Running time v.s. computational complexity General description.
CS223 Algorithms D-Term 2013 Instructor: Mohamed Eltabakh WPI, CS Introduction Slide 1.
CS 103 Discrete Structures Lecture 01 Introduction to the Course
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
Analyzing algorithms & Asymptotic Notation BIO/CS 471 – Algorithms for Bioinformatics.
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 1: The Role of Algorithms in Computing (slides by N. Adlai A. DePano)
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
HKOI 2005 Training Introduction to Algorithms Alan, Tam Siu Lung.
Introduction to Genetic Algorithms. Genetic Algorithms We’ve covered enough material that we can write programs that use genetic algorithms! –More advanced.
1 BIM304: Algorithm Design Time: Friday 9-12am Location: B4 Instructor: Cuneyt Akinlar Grading –2 Midterms – 20% and 30% respectively –Final – 30% –Projects.
CSE 340: Review (at last!) Measuring The Complexity Complexity is a function of the size of the input O() Ω() Θ() Complexity Analysis “same order” Order.
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
Design and Analysis of Algorithms Introduction Instructors:1. B V Kiran Mayee, 2. A Madhavi
Algorithms Design and Analysis CS Course description / Algorithms Design and Analysis Course name and Number: Algorithms designs and analysis –
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Copyright © 2014 Curt Hill Algorithm Analysis How Do We Determine the Complexity of Algorithms.
Lecture 2: More Examples CS 341: Algorithms Thursday, May 5 th
CS16: Introduction to Algorithms and Data Structures
Algorithms Sorting – Part 3.
Design and Analysis of Algorithms
Advanced Algorithms Analysis and Design
Welcome to the Course of Advanced Algorithm Design
Design and Analysis of Algorithms (09 Credits / 5 hours per week)
Data Structures Lab Algorithm Animation.
Lecture 1: Introduction
Analysis of Algorithms
Unit 1. Sorting and Divide and Conquer
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Introduction to the Design and Analysis of Algorithms
Summary of lectures Introduction to Algorithm Analysis and Design (Chapter 1-3). Lecture Slides Recurrence and Master Theorem (Chapter 4). Lecture Slides.
Introduction of ECE665 Computer Algorithms
EECS 203 Lecture 20 More Graphs.
Data Structures Algorithms: (Slides to be Adopted from Goodrich and aligned with Weiss' book) Instructor: Ganesh Ramakrishnan
CS 3343: Analysis of Algorithms
CS 583 Fall 2006 Analysis of Algorithms
Design and Analysis of Computer Algorithm (CS575-01)
CS 2210 Discrete Structures Algorithms and Complexity
Definition In simple terms, an algorithm is a series of instructions to solve a problem (complete a task) We focus on Deterministic Algorithms Under the.
Design and Analysis of Algorithms (07 Credits / 4 hours per week)
Algorithm design and Analysis
Foundations II: Data Structures and Algorithms
Data Structures and Algorithms
Objective of This Course
Computational Complexity
CMPT 438 Algorithms Instructor: Tina Tian.
Discrete Mathematics CS 2610
Searching, Sorting, and Asymptotic Complexity
CSC 380: Design and Analysis of Algorithms
David Kauchak cs161 Summer 2009
Design and Analysis of Algorithms
Algorithms CSCI 235, Spring 2019 Lecture 36 P vs
Design and Analysis of Algorithms (04 Credits / 4 hours per week)
Divide and Conquer Merge sort and quick sort Binary search
COMP 122 – Design and Analysis of Algorithms
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Advanced Analysis of Algorithms
CS 2210 Discrete Structures Algorithms and Complexity
Presentation transcript:

Trevor Brown trevor.brown@uwaterloo.ca CS 341: Algorithms Trevor Brown trevor.brown@uwaterloo.ca

A bit about me Interests Big multi-core systems Fast data structures and algorithms … Gamer Ex-metal drummer

Course mechanics Ask questions! Need an account in the student.cs environment Course website: https://www.student.cs.uwaterloo.ca/~cs341/ Syllabus, calendar, policies, slides, assignments… Piazza: Join it. Use it to ask even more questions. Learn: Grades and assignment solutions

Course syllabus Read it Mark important dates

Academic offenses Sharing ideas: OK Sharing code / answers: BAD Using solutions from elsewhere: BAD Don’t cheat

Grading scheme for CS 341 Midterm (25%) Tuesday, Feb. 26, 2019, 7:00-8:50 PM Assignments (30%) There will be five assignments. Work alone Final (45%) Due Friday Jan. 25 Due Friday Feb. 8 Due Friday March 1 Due Friday March 22 Due Friday April 5

Assignments All sections have same assignments, midterm and final Assignments due at 6:00 PM on the due date No late submissions Notify me long before the deadline of severe problems that will cause you to miss an assignment

Textbook Introduction to Algorithms, Third Edition, by Cormen, Leiserson, Rivest and Stein, MIT Press, 2009. Available online for free via the library website! You are expected to know entire textbook sections, as listed on course website or Learn all the material presented in class

Why is CS 341 Important For You? Algorithms is the heart of CS Appears in later courses Appears in technical interviews Designing algorithms is creative work; can be fun!

Only some of this covered today! Table of Contents Only some of this covered today! Introductory material What are algorithms and computational problems? What is algorithm analysis? The 3SUM problem Reductions Order notation Loop analysis techniques

What is a Computational Problem? What is an Algorithm? Think of an algorithm as a software program. Input  algorithm  output Informally: A well-defined procedure (sequence of steps) to solve a computational problem What is a Computational Problem? Informally: A description of some (class of) input, and the desired output

Examples of computational problems Input Output Sorting An array of integers (in arbitrary order) Same array of integers in increasing order Matrix Multiplication Two n x n matrices A, B C=A*B Traveling Salesman Problem A set S of cities, and distances between each pair of cities Shortest possible path that visits each city, and returns to the origin city

Sorting

Matrix multiplication Input: two n x n matrices A and B Output: an n x n matrix representing A * B 2 1 5 3 4 6 1 3 4 2 7 A B 19 41 18 13 25 27 49 20 19 2*1 + 1*2 + 5*3 C

Traveling salesman problem Input: map of cities & distances between each pair Output: shortest path that (1) visits all cities, and (2) starts and ends at the same city c2 How would you provide this input to a program? 5 (hours) 3 c1 c3 3 2 4 8 7 2 1 9 c5 c4

Traveling salesman problem Input: map of cities & distances between each pair Output: shortest path that (1) visits all cities, and (2) starts and ends at the same city c2 5 (hours) 3 c1 c3 3 2 4 8 7 2 1 How would you output this path to the user? 9 c5 c4

Analysis of algorithms Every software program uses resources Algorithms are no exception Example Resources: CPU instructions/cycles  typically called time Memory (RAM)  typically called space Network I/O or communication (not covered in this course)

Analysis of algorithms Analysis answers questions about how many resources an algorithm uses: How much time does it take to run Algorithm X? How much space does Algorithm X use? In this course we will typically analyze time Formally: number of CPU instructions performed

Taxonomy of algorithms Serial vs Parallel Serial: One instruction at a time Parallel: Multiple instructions at once Deterministic vs Randomized D: On multiple runs on same input, always do same thing R: On multiple runs on same input, may do different things Exact vs Approximate Exact: exact solution to the problem Approximate: only approximate solution to the problem This course: Serial, deterministic, exact

Do all problems have fast solutions? For some problems, such as the traveling salesman problem, we have only found exponential time algorithms. These algorithms exponentially longer to solve the problem as the number of cities increases! Informally: adding one city doubles the runtime We want polynomial time solutions Open question (P vs NP): are there problems so hard that any solution must take exponential time on some inputs?

Tractable vs intractable Terminology used in the course Informally: a problem is tractable if: An algorithm exists that can solve the problem for any possible input in polynomial time Informally: a problem is intractable if: It is (probably) not tractable I.e., all known algorithms that solve the problem take exponential time for some inputs

CS 341 Diagram Fundamental (& Fast) Algorithms to Tractable Problems MergeSort Strassen’s MM BFS/DFS Dijkstra’s SSSP Kruskal’s MST Floyd Warshall APSP Topological Sort … Common Algorithm Design Paradigms Divide-and-Conquer Greedy Dynamic Programming Exhaustive search / brute force Intractable Problems Mathematical Tools to Analyze Algorithms P vs NP Poly-time Reductions Undecidability Big-oh notation Recursion Tree Master method Substitution method Exchange Arguments Greedy-stays-ahead Arguments Other (Last Lecture) Parallel Algorithms

CS 341: Before  After Fundamental Algorithms Fundamental Algorithm Design Paradigms Tractability/Intractability Math Techniques for Algorithm Analysis

Some real material Let’s briefly study the sorting problem Input: array X containing n integers X[1], X[2], …, X[n] Output: the same array, but with the n integers appearing in increasing order 10 2 37 5 9 55 20 2 5 9 10 20 37 55

A simple sorting algorithm Selection sort Idea is simple Find the smallest element and swap it with X[1] Find the next smallest element and swap it with X[2] ... Repeat until array is sorted

SelectionSort Simulation 10 2 37 5 9 55 20 minElement: 2 minIndex: 2

SelectionSort Simulation 2 10 37 5 9 55 20 minElement: 5 minIndex: 4

SelectionSort Simulation 2 5 37 10 9 55 20 minElement: 9 minIndex: 5

SelectionSort Simulation 2 5 9 10 37 55 20 minElement: 10 minIndex: 4

SelectionSort Simulation 2 5 9 10 37 55 20 minElement: 20 minIndex: 7

SelectionSort Simulation 2 5 9 10 20 55 37 minElement: 37 minIndex: 7

SelectionSort Simulation 2 5 9 10 20 37 55 Final Output

Find i-th smallest element Pseudocode For each array slot Find i-th smallest element Swap it into slot i

Analysis Recall: Input is array X of size n We refer to n the problem size When we analyze the algorithm, we will express the running time as a function of n Running time must to be a function of n. Why? Recall: running time = # of CPU instructions

Analyzing this algorithm Covered roughly in a few different ways on the board: c*n2 steps, where c is some constant