Outline. CS38 Introduction to Algorithms. Administrative Stuff. Administrative Stuff. Motivation/Overview. Administrative Stuff

Similar documents
Algorithms for External Memory Lecture 6 Graph Algorithms - Weighted List Ranking

Dynamic Programming. Lecture #8 of Algorithms, Data structures and Complexity. Joost-Pieter Katoen Formal Methods and Tools Group

1 Disjoint-set data structure.

Simple strategy Computes shortest paths from the start note

Learning Convention Propagation in BeerAdvocate Reviews from a etwork Perspective. Abstract

Outline: Software Design

Incremental Mining of Partial Periodic Patterns in Time-series Databases

Dynamic Algorithms Multiple Choice Test

Recursion examples: Problem 2. (More) Recursion and Lists. Tail recursion. Recursion examples: Problem 2. Recursion examples: Problem 3

Outline. CS38 Introduction to Algorithms. Graphs. Graphs. Graphs. Graph traversals

Data Structures in Java

On - Line Path Delay Fault Testing of Omega MINs M. Bellos 1, E. Kalligeros 1, D. Nikolos 1,2 & H. T. Vergos 1,2

Greedy Algorithms 1 {K(S) K(S) C} For large values of d, brute force search is not feasible because there are 2 d {1,..., d}.

Announcements. HW3 is graded. Average is 81%

Calculation of typical running time of a branch-and-bound algorithm for the vertex-cover problem

CA Test Data Manager 4.x Implementation Proven Professional Exam (CAT-681) Study Guide Version 1.0

CA Release Automation 5.x Implementation Proven Professional Exam (CAT-600) Study Guide Version 1.1

Solutions to relevant spring 2000 exam problems

Data Structures and Algorithms. Chapter 7. Graphs

COT 6405 Introduction to Theory of Algorithms

Data Structures and Algorithms. Werner Nutt

Layout Compliance for Triple Patterning Lithography: An Iterative Approach

Copyright 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin Introduction to the Design & Analysis of Algorithms, 2 nd ed., Ch.

A Dual-Hamiltonian-Path-Based Multicasting Strategy for Wormhole-Routed Star Graph Interconnection Networks

Sparse Certificates for 2-Connectivity in Directed Graphs

Directed Rectangle-Visibility Graphs have. Abstract. Visibility representations of graphs map vertices to sets in Euclidean space and

1 The Knuth-Morris-Pratt Algorithm

Graphs. CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington

Machine Vision. Laboratory Exercise Name: Student ID: S

Announcements. CSEP 521 Applied Algorithms. Announcements. Polynomial time efficiency. Definitions of efficiency 1/14/2013

Chapter 22. Elementary Graph Algorithms

Adobe Certified Associate

Algorithm Design, Anal. & Imp., Homework 4 Solution

Review for Midterm Exam

Lecture 13: Graphs I: Breadth First Search

Basic Graph Algorithms

Fuzzy Meta Node Fuzzy Metagraph and its Cluster Analysis

Facility Location: Distributed Approximation

A Compressed Breadth-First Search for Satisfiability

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

Graph: representation and traversal

Figure 1: A directed graph.

Chapter 2: Introduction to Maple V

Algorithmica 2002 Springer-Verlag New York Inc.

Parametric Abstract Domains for Shape Analysis

CA Agile Requirements Designer 2.x Implementation Proven Professional Exam (CAT-720) Study Guide Version 1.0

22.1 Representations of graphs

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch]

Problem set 2. Problem 1. Problem 2. Problem 3. CS261, Winter Instructor: Ashish Goel.

Homework Assignment #3 Graph

Basic Graph Algorithms (CLRS B.4-B.5, )

Graph Representation

Lecture 22 Tuesday, April 10

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

Implementing Algorithms

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

Path Sharing and Predicate Evaluation for High-Performance XML Filtering*

To Do. Assignment Overview. Outline. Mesh Viewer (3.1) Mesh Connectivity (3.2) Advanced Computer Graphics (Spring 2013)

W4231: Analysis of Algorithms

PROJECT PERIODIC REPORT

Definitions Homework. Quine McCluskey Optimal solutions are possible for some large functions Espresso heuristic. Definitions Homework

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Lecture 3: Graphs and flows

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees

Recommendation Subgraphs for Web Discovery

Design and Analysis of Algorithms

Computational Biology 6.095/6.895 Database Search Lecture 5 Prof. Piotr Indyk

SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY

Automatic Physical Design Tuning: Workload as a Sequence Sanjay Agrawal Microsoft Research One Microsoft Way Redmond, WA, USA +1-(425)

12/9/14. CS151 Fall 20124Lecture (almost there) 12/6. Graphs. Seven Bridges of Königsberg. Leonard Euler

Elementary Graph Algorithms

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)

Data Structures. Elementary Graph Algorithms BFS, DFS & Topological Sort

Algorithms and Data Structures. Algorithms and Data Structures. Algorithms and Data Structures. Algorithms and Data Structures

HEXA: Compact Data Structures for Faster Packet Processing

Figure 1. LBP in the field of texture analysis operators.

CS 170 Spring 2000 Solutions and grading standards for exam 1 Clancy

Compilation Lecture 11a. Register Allocation Noam Rinetzky. Text book: Modern compiler implementation in C Andrew A.

Abstract. We describe a parametric hybrid Bezier patch that, in addition. schemes are local in that changes to part of the data only aect portions of

CS 361 Data Structures & Algs Lecture 15. Prof. Tom Hayes University of New Mexico

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

ON CHARACTERIZING TERRAIN VISIBILITY GRAPHS

Interconnection Styles

Pipelined Multipliers for Reconfigurable Hardware

Drawing lines. Naïve line drawing algorithm. drawpixel(x, round(y)); double dy = y1 - y0; double dx = x1 - x0; double m = dy / dx; double y = y0;

Outlines: Graphs Part-2

CSC263 Week 8. Larry Zhang.

Algorithm Design and Analysis

Definition f(n) = O(g(n)) if there exists n 0, c such that for all n n 0, f(n) cg(n). g is an asymptotic upper bound on f.

Gray Codes for Reflectable Languages

Graph Algorithms. Definition

Lecture 8: Graph-theoretic problems (again)

Copyright 2000, Kevin Wayne 1

Multi-Level Modeling of Concurrent and Distributed Systems

Shortest Paths in Directed Graphs

Unweighted directed graphs

WEEK 1 CLASS NOTES AARON G. CASS

Data Structures and Algorithms. Werner Nutt

Transcription:

Outline CS38 Introdution to Algorithms Leture 1 April 1, 2014 administrative stuff motivation and overview of the ourse stale mathings example graphs, representing graphs graph traversals (BFS, DFS) onnetivity, topologial sort, strong onnetivity April 1, 2014 CS38 Leture 1 2 Administrative Stuff Text: Introdution to Algorithms (3 rd Edition) y Cormen, Leiserson, Rivest, Stein CLRS reommended ut not required letures self-ontained slides posted online Administrative Stuff weekly homework ollaoration in groups of 2-3 enouraged separate write-ups (larity ounts) midterm and final indistinguishale from homework exept umulative, no ollaoration allowed April 1, 2014 CS38 Leture 1 3 April 1, 2014 CS38 Leture 1 4 Administrative Stuff no programming in this ourse things I assume you are familiar with: programming and asi data strutures: arrays, lists, staks, queues asymptoti notation ig-oh sets, graphs proofs, espeially indution proofs exposure to NP-ompleteness Computaility and Complexity Algorithms Systems and Software Design and Implementation Theory April 1, 2014 CS38 Leture 1 5 April 1, 2014 CS38 Leture 1 6 1

at the heart of programs lie algorithms in this ourse algorithms means: astrating prolems from aross appliation domains worst ase analysis asymptoti analysis ( ig-oh ) main figure of merit rigorous proofs paradigm (vs. heuristis ) algorithms as a key tehnology think aout: mapping/navigation Google searh Shazam word proessing (spelling orretion, layout ) ontent delivery and streaming video games (graphis, rendering ) ig data (querying, learning ) April 1, 2014 CS38 Leture 1 7 April 1, 2014 CS38 Leture 1 8 In a perfet world for eah prolem we would have an algorithm the algorithm would e the fastest possile What would CS look like in this world? Our world (fortunately) is not so perfet: for many prolems we know emarrassingly little aout what the fastest algorithm is multiplying two integers or two matries fatoring an integer into primes determining shortest tour of given n ities for many prolems we suspet fast algorithms are impossile (NP-omplete prolems) for some prolems we have unexpeted and lever algorithms (we will see many of these) April 1, 2014 CS38 Leture 1 9 April 1, 2014 CS38 Leture 1 10 Two main themes: algorithm design paradigms algorithms for fundamental prolems (data strutures as needed) definitions and onventions NP-ompleteness and introdution to approximation algorithms April 1, 2014 CS38 Leture 1 11 April 1, 2014 CS38 Leture 1 12 2

What is a prolem? Some examples: given n integers, produe a sorted list given a graph and nodes s and t, find a shortest path from s to t given an integer, find its prime fators prolem assoiates eah input to an output a prolem is a funtion: f:σ * Σ * What is an algorithm? a prolem is a funtion: f:σ * Σ * formally: an algorithm is a Turing Mahine that omputes funtion f more informal: a preisely speified sequene of asi instrutions omputing f level of detail is a judgment all high-level desription, detailed pseudo-ode April 1, 2014 CS38 Leture 1 13 April 1, 2014 CS38 Leture 1 14 Underlying model Offiially, Random Aess Mahine (RAM) essentially, low level programming language like assemly ode Will not ome up in this ourse We all an distinguish etween, e.g. x à i-th element of array A (single step) x à minimum element of array A (not a single step) Worst-ase analysis Figure of merit: resoure usage running time (primary for this ourse) storage spae others Always measure resoure usage via: funtion of the input size value of the fn. is the maximum quantity of resoure used over all inputs of given size alled worst-ase analysis April 1, 2014 CS38 Leture 1 15 April 1, 2014 CS38 Leture 1 16 Asymptoti notation Measure time/spae omplexity using asymptoti notation ( ig-oh notation ) disregard lower-order terms in running time disregard oeffiient on highest order term example: f(n) = 6n 3 + 2n 2 + 100n + 102781 f(n) is order n 3 write f(n) = O(n 3 ) Asymtoti notation aptures ehavior for large n 3n 2 +100 2 n /30 f(n) n! April 1, 2014 CS38 Leture 1 17 April 1, 2014 CS38 Leture 1 18 3

Asymptoti notation Definition: given funtions f,g:n R +, we say f(n) = O(g(n)) if there exist positive integers, n 0 suh that for all n n 0 f(n) g(n). meaning: f(n) is (asymptotially) less than or equal to g(n) if g > 0 an assume n 0 = 0, y setting = max 0 n n0 {, f(n)/g(n)} Asymptoti notation fats logarithmi : O(log n) log n = (log 2 n)/(log 2 ) so log n = O(log 2 n) for any onstant ; therefore suppress ase when write it polynomial : O(n ) = n O(1) also: O(log n) = O(n ) = n O(1) exponential : O(2 nδ ) for δ > 0 eah ound asymptotially less than next April 1, 2014 CS38 Leture 1 19 April 1, 2014 CS38 Leture 1 20 Why worst ase, asymptoti? Why worst-ase? well-suited to rigorous analysis, simple stringent requirement etter Why asymptoti? not produtive to fous on fine distintions are aout ehavior on large inputs general-purpose alg. should e salale exposes genuine arriers/motivates new ideas example April 1, 2014 CS38 Leture 1 21 April 1, 2014 CS38 Leture 1 22 Motivation: n medial students and n hospitals eah student has ranking of hospitals eah hospital has ranking of students Goal: math eah student to a hospital Goal: make the mathing stale Definition: (student x, hospital y) pair unstale if x prefers y to its math and y prefers x to its math Captures many settings, e.g., employee/employer students/dorms men/women Usually desried via men/women: ranked list of n women for eah of n men ranked list of n men for eah of n women f produe a stale mathing (no unstale pairs) April 1, 2014 CS38 Leture 1 23 April 1, 2014 CS38 Leture 1 24 4

Does a stale mathing always exist? Is there an effiient algorithm to find one? We have a well-defined prolem a proposed algorithm Now we need to prove orretness ound running time, possily requiring filling in implementation details April 1, 2014 CS38 Leture 1 25 April 1, 2014 CS38 Leture 1 26 mathed, and with no unstale pair Proof: terminates? April 1, 2014 CS38 Leture 1 27 mathed, and with no unstale pair Proof: all mathed? April 1, 2014 CS38 Leture 1 28 mathed, and with no unstale pair Proof: unstale pair (m, w)? April 1, 2014 CS38 Leture 1 29 mathed, and S ontaining no unstale pair Proof: terminates: only n 2 possile proposals, 1 per iteration all mathed: suppose not. Then some m unmathed and some w unmathed. So w never proposed to. But m proposed to everyone if ends unmathed. April 1, 2014 CS38 Leture 1 30 5

mathed, and S ontaining no unstale pair Proof: pair (m, w) not in S ase 1: m never proposed to w, ) m prefers his urrent partner ase 2: m proposed to w ) w rejeted m (in line 6 or line 5) in oth ases (m, w) is not an unstale pair. April 1, 2014 CS38 Leture 1 31 Lemma: an implement with running time O(n 2 ) Proof: reate two arrays wife, husand wife[m] = w if (m,w) in S, 0 if unmathed (same for husand) April 1, 2014 CS38 Leture 1 32 implementing step 5? for eah preferene list pref an reate inv-pref via: for i = 1 to n do inv-pref[pref[i]] = i w prefers m to m iff inv-pref[m] < inv-pref[m ] O(n 2 ) preproessing; O(1) time for eah iteration of loop We proved: Theorem (Gale-Shapley 62): there is an O(n 2 ) time algorithm that is given n rankings of women y eah of n men n rankings of men y eah of n women and outputs a stale mathing of men to women. April 1, 2014 CS38 Leture 1 34 Graphs Basi graph algorithms Graph G = (V, E) direted or undireted notation: n = V, m = E (note: m n 2 ) adjaeny list or adjaeny matrix a a a 0 1 1 0 0 0 0 1 0 a April 1, 2014 CS38 Leture 1 35 April 1, 2014 CS38 Leture 1 36 6

Graphs Graphs model many things physial networks (e.g. roads) ommuniation networks (e.g. internet) information networks (e.g. the we) soial networks (e.g. friends) dependeny networks (e.g. topis in this ourse) so many fundamental algorithms operate on graphs Graphs Graph terminology: an undireted graph is onneted if there is a path etween eah pair of verties a tree is a onneted, undireted graph with no yles; a forest is a olletion of disjoint trees a direted graph is strongly onneted if there is a path from x to y and from y to x, 8 x,y2v a DAG is a Direted Ayli Graph April 1, 2014 CS38 Leture 1 37 April 1, 2014 CS38 Leture 1 38 Graph traversals Graph traversal algorithm: visit some or all of the nodes in a graph, laeling them with useful information readth-first: useful for undireted, yields onnetivity and shortest-paths information depth-first: useful for direted, yields numering used for topologial sort strongly-onneted omponent deomposition Breadth first searh BFS(undireted graph G, starting vertex s) 1. for eah vertex v, v.olor = white, v.dist = 1, v.pred = nil 2. s.olor = grey, s.dist = 0, s.pred = nil 3. Q = ;; ENQUEUE(Q, s) 4. WHILE Q is not empty u = DEQUEUE(Q) 5. for eah v adjaent to u 6. IF v.olor = white THEN 7. v.olor = grey, v.dist = u.dist + 1, v.pred = u 8. ENQUEUE(Q, v) 9. u.olor = lak Lemma: BFS runs in time O(m + n), when G is represented y an adjaeny list. Proof? April 1, 2014 CS38 Leture 1 39 Breadth first searh BFS(undireted graph G, starting vertex s) 1. for eah vertex v, v.olor = white, v.dist = 1, v.pred = nil 2. s.olor = grey, s.dist = 0, s.pred = nil 3. Q = ;; ENQUEUE(Q, s) 4. WHILE Q is not empty u = DEQUEUE(Q) 5. for eah v adjaent to u 6. IF v.olor = white THEN 7. v.olor = grey, v.dist = u.dist + 1, v.pred = u 8. ENQUEUE(Q, v) 9. u.olor = lak BFS example from CLRS Lemma: BFS runs in time O(m + n), when G is represented y an adjaeny list. Proof: eah vertex enqueued at most 1 time; its adj. list sanned one; O(1) work for eah neighor 7