Lecture 1 Introduction

Report 3 Downloads 197 Views
Lecture 1 Introduction

Monday, 25 July 2016 10:02 AM

Reduction Reducing interval scheduling to independent set problem  Each interval becomes a node  Node is connected if interval overlaps Reducing bipartite matching to independent set problem  Each edge becomes a node  Node is connected if the end shares an end Polynomial time If you double the input size, algorithm slows down by a constant factor An algorithm is efficient if it's worst case run time is polynomial. Asymptotic Order of Growth Upper bounds

T(n) is guaranteed to be smaller Gives worst case run time

Lower bounds

T(n) is guaranteed to be larger Gives best case run time

Tight bounds

T(n) is both upper and lower bound Gives best approximation of running time

Transitivity and Additivity

O

Order -- from shortest to longest running Logarithms < Polynomials < Exponentials

Lab 01

Wednesday, 27 July 2016 8:52 AM

Which asymptotic growth is faster?  Put the two you want to compare in a ratio  Find the limit as n approaches infinity

Lecture 2 Graphs

Monday, 1 August 2016 10:03 AM

Undirected and directed graphs Graph representation 1. Adjacency matrix 2. Adjacency list Adjacency matrix  n by n matrix  Two cells to list an edge  Checking for an specific edge on a node is O(1)  Checking for all edges is O(n^2)  Space is O(n^2) o Not very good for large graphs

Adjacency list  Node indexed as an array  Checking for a specific edge on a node is O(deg(v))  Checking for all edges is O(n+m)  Space is O(2m+n) = O(n+m) Definitions Path

A sequence of nodes such that each consecutive pair is joined by an edge

Simple path

All nodes in the path are distinct

Connected

There is a path between every pair of nodes

Cycle

A path starting and ending on the same node -- all node are distinct

Trees. Any two statements will imply the third:  G is connected  G does not contain a cycle  G has n-1 edges Graph traversal -- BFS and DFS  BFS produces a tree rooted at the start vertex on a set of nodes reachable from the start node BFS 



Runs O(n+m) using a adjacency list o Each edge is looked at twice, once for each endpoint o O(n+2m) = O(n+m) Runs O(n^2) o To find the neighbours, look through the vector

Transitive closure  DFS or BFS on each node  Runs O(nm) using an adjacency list  From O(n^2 + nm) = O(nm), because nm > n^2 DFS 

Runs O(n+m) using an adjacency list

Testing bipartiteness Lemma: If a graph is bipartite, it cannot contain an odd length cycle

Proof?  You can pick each layer to be alternating colours: red and blue  If we have an edge connecting two nodes of the same layer, then there exists an odd length cycle