Compsci 100, Spring 2009 12.1 Graphs, the Internet, and Everything

Slides:



Advertisements
Similar presentations
CS 206 Introduction to Computer Science II 04 / 01 / 2009 Instructor: Michael Eckmann.
Advertisements

§3 Shortest Path Algorithms Given a digraph G = ( V, E ), and a cost function c( e ) for e  E( G ). The length of a path P from source to destination.
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graphs - II CS 2110, Spring Where did I leave that book?
CompSci 100e Program Design and Analysis II April 19, 2011 Prof. Rodger CompSci 100e, Spring
Problem Solving Agents A problem solving agent is one which decides what actions and states to consider in completing a goal Examples: Finding the shortest.
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
CS171 Introduction to Computer Science II Graphs Strike Back.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
Graph & BFS.
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
Graph & BFS Lecture 22 COMP171 Fall Graph & BFS / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
COMP171 Depth-First Search.
Graphs. Graphs Many interesting situations can be modeled by a graph. Many interesting situations can be modeled by a graph. Ex. Mass transportation system,
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
CPS Graphs, the Internet, and Everything
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Computer Science 112 Fundamentals of Programming II Graph Algorithms.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
SPANNING TREES Lecture 21 CS2110 – Spring
Sept Elementary Graph Algorithms Graph representation Graph traversal -Breadth-first search -Depth-first search Parenthesis theorem.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Representing and Using Graphs
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 5 Graph Algorithms.
Data Structures and Algorithms Ver. 1.0 Session 17 Objectives In this session, you will learn to: Implement a graph Apply graphs to solve programming problems.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Compsci 100, Spring Graphs, the Internet, and Everything
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
CPS 100, Spring Graphs, the Internet, and Everything
CompSci Problem: finding subsets l See CodeBloat APT, requires finding sums of all subsets  Given {72, 33, 41, 57, 25} what is sum closest (not.
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees  Definitions  Minimum spanning trees  3 greedy algorithms (incl. Kruskal’s & Prim’s)
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Graphs Slide credits:  K. Wayne, Princeton U.  C. E. Leiserson and E. Demaine, MIT  K. Birman, Cornell U.
CompSci Graphs, the Internet, and Everything
CompSci The Internet l How valuable is a network? ä Metcalfe’s Law l Domain Name System: translates betweens names and IP addresses l Properties.
Compsci 101.2, Fall Plan for eleven-four l Thinking about APTs and test problems  How do you choose: list, string, set, dictionary  Experience?
CPS Graphs: Structures and Algorithms l How do packets of bits/information get routed on the internet  Message divided into packets on client.
Graphs + Shortest Paths David Kauchak cs302 Spring 2013.
Graph Searching CSIT 402 Data Structures II. 2 Graph Searching Methodology Depth-First Search (DFS) Depth-First Search (DFS) ›Searches down one path as.
Graphs David Kauchak cs302 Spring Admin HW 12 and 13 (and likely 14) You can submit revised solutions to any problem you missed Also submit your.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
The Internet Domain Name System: translates betweens names and IP addresses Properties of the Internet Heterogeneity Redundancy Packet-switched 604 million.
A vertex u is reachable from vertex v iff there is a path from v to u.
Graphs Representation, BFS, DFS
Graphs, the Internet, and Everything
Graphs, the Internet, and Everything
Owen Astrachan Jeff Forbes December 6, 2018
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
Graphs Representation, BFS, DFS
Graphs Chapter 11 Objectives Upon completion you will be able to:
CSE 373: Data Structures and Algorithms
Graph Traversal Lecture 18 CS 2110 — Spring 2019.
Spanning Trees Lecture 20 CS2110 – Spring 2015.
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Compsci 100, Spring Graphs, the Internet, and Everything

Compsci 100, Spring Graphs: Structures and Algorithms l How do packets of bits/information get routed on the internet  Message divided into packets on client (your) machine  Packets sent out using routing tables toward destination Packets may take different routes to destination What happens if packets lost or arrive out-of-order?  Routing tables store local information, not global (why?) l What about The Oracle of Bacon, Erdos Numbers, and Word Ladders?The Oracle of BaconErdos Numbers  All can be modeled using graphs  What kind of connectivity does each concept model? l Graphs are everywhere in the world of algorithms (world?)

Compsci 100, Spring Word ladder (not really new example)

Compsci 100, Spring Old and New: Fan Chung Graham l Graphs are everywhere l

Compsci 100, Spring Tim Berners-Lee I want you to realize that, if you can imagine a computer doing something, you can program a computer to do that. Unbounded opportunity... limited only by your imagination. And a couple of laws of physics. l TCP/IP, HTTP  How, Why, What, When?

Compsci 100, Spring Vocabulary l Graphs are collections of vertices and edges (vertex also called node)  Edge connects two vertices Direction can be important, directed edge, directed graph Edge may have associated weight/cost l A vertex sequence v 0, v 1, …, v n-1 is a path where v k and v k+1 are connected by an edge.  If some vertex is repeated, the path is a cycle  A graph is connected if there is a path between any pair of vertices NYC Phil Boston Wash DC LGALAX ORD DCA $186 $412 $1701 $441

Compsci 100, Spring Graph questions/algorithms l What vertices are reachable from a given vertex?  Two standard traversals: depth-first, breadth-first  Find connected components, groups of connected vertices l Shortest path between any two vertices (weighted graphs?)  Breadth first search is storage expensive  Dijkstra’s algorithm is efficient, uses a priority queue too! l Longest path in a graph  No known efficient algorithm l Visit all vertices without repeating? Visit all edges?  With minimal cost? Hard!

Compsci 100, Spring Depth, Breadth, other traversals l We want to visit every vertex that can be reached from a specific starting vertex (we might try all starting vertices)  Make sure we don't visit a vertex more than once Why isn't this an issue in trees? Mark vertex as visited, use set/array/map for this –Can keep useful information to help with visited status  Order in which vertices visited can be important  Storage and runtime efficiency of traversals important l What other data structures do we have: stack, queue, …  What happens when we traverse using priority queue?

Compsci 100, Spring Breadth first search l In an unweighted graph this finds the shortest path between a start vertex and every vertex  Visit every node one away from start  Visit every node two away from start This is every node one away from a node one away  Visit every node three away from start, … l Put vertex on queue to start (initially just one)  Repeat: take vertex off queue, put all adjacent vertices on  Don’t put a vertex on that’s already been visited (why?)  When are 1-away vertices enqueued? 2-away? 3-away?  How many vertices on queue?

Compsci 100, Spring Code for breadth first public void breadth(String vertex){ Set visited = new TreeSet (); Queue q = new LinkedList (); q.add(vertex); visited.add(vertex); while (q.size() > 0) { String current = q.remove(); // process current for(each v adjacent to current){ if (!visited.contains(v)){// not visited visited.add(v); q.add(v); }

Compsci 100, Spring Pseudo-code for depth-first search void depthfirst(String vertex){ if (! alreadySeen(vertex)){ markAsSeen(vertex); System.out.println(vertex); for(each v adjacent to vertex) { depthfirst(v); } l Clones are stacked up, problem? Can we make use of stack explicit?

Compsci 100, Spring BFS compared to DFS public Set bfs(Graph.Vertex start){ Set visited = new TreeSet (); Queue qu = new LinkedList (); visited.add(start); qu.add(start); while (qu.size() > 0){ Graph.Vertex v = qu.remove(); for(Graph.Vertex adj : myGraph.getAdjacent(v)){ if (! visited.contains(adj)) { visited.add(adj); qu.add(adj); } return visited; }

Compsci 100, Spring BFS becomes DFS public Set dfs(Graph.Vertex start){ Set visited = new TreeSet (); Queue qu = new LinkedList (); visited.add(start); qu.add(start); while (qu.size() > 0){ Graph.Vertex v = qu.remove(); for(Graph.Vertex adj : myGraph.getAdjacent(v)){ if (! visited.contains(adj)) { visited.add(adj); qu.add(adj); } return visited; }

Compsci 100, Spring DFS arrives public Set dfs(Graph.Vertex start){ Set visited = new TreeSet (); Stack qu = new Stack (); visited.add(start); qu.push(start); while (qu.size() > 0){ Graph.Vertex v = qu.pop(); for(Graph.Vertex adj : myGraph.getAdjacent(v)){ if (! visited.contains(adj)) { visited.add(adj); qu.push(adj); } return visited; }

Compsci 100, Spring What is the Internet? l The Internet was originally designed as an "overlay" network running on top of existing phone and other networks. It is based on a small set of software protocols that direct routers inside the network to forward data from source to destination, while applications run on the Internet to rapidly scale into a critical global service. However, this success now makes it difficult to create and test new ways of protecting it from abuses, or from implementing innovative applications and services.

Compsci 100, Spring How does the Internet work? l Differences between the Internet and phone networks  Dedicated circuits/routes  Distributed, end-to-end l Where is the intelligence?  Not in the network, per se, in the design and the ends  End-to-end Arguments in System Design End-to-end Arguments in System Design l Success of , web, etc., relies on not building intelligence into the network  What about overlay networks?  What about PlanetLab?PlanetLab

Compsci 100, Spring Barbara Liskov l 2008 Winner of Turing Award l First woman to earn PhD in CS in US. l What I am very interested in today is about storage in the cloud....I think that this is going to become the universal way of doing business....My major research focus today is what are the properties that a storage service has to provide in order for me to be really happy with it.

Compsci 100, Spring Graph implementations l Typical operations on graph:  Add vertex  Add edge (parameters?)  getAdjacent(vertex)  getVertices(..)  String->Vertex (vice versa) l Different kinds of graphs  Lots of vertices, few edges, sparse graph Use adjacency list  Lots of edges (max # ?) dense graph Use adjacency matrix Adjacency list

Compsci 100, Spring Graph implementations (continued) l Adjacency matrix  Every possible edge represented, how many? l Adjacency list uses O(V+E) space  What about matrix?  Which is better? l What do we do to get adjacent vertices for given vertex?  What is complexity?  Compared to adjacency list? l What about weighted edges? TF …

Compsci 100, Spring Shortest path in weighted graph l We need to modify approach slightly for weighted graph  Edges have weights, breadth first by itself doesn’t work  What’s shortest path from A to F in graph below? l Use same idea as breadth first search  Don’t add 1 to current distance, add ???  Might adjust distances more than once  What vertex do we visit next? l What vertex is next is key  Use greedy algorithm: closest  Huffman is greedy, … D E A B C F

Compsci 100, Spring What about connected components? l What computers are reachable from this one? What people are reachable from me via acquaintanceship?  Start at some vertex, depth-first search (why not breadth)? Mark nodes visited  Repeat, starting from an unvisited vertex (until all visited) l What is minimal size of a component? Maximal size?  What is complexity of algorithm in terms of V and E? l What algorithms does this lead to in graphs?

Compsci 100, Spring Greedy Algorithms l A greedy algorithm makes a locally optimal decision that leads to a globally optimal solution  Huffman: choose two nodes with minimal weight, combine Leads to optimal coding, optimal Huffman tree  Making change with American coins: choose largest coin possible as many times as possible Change for $0.63, change for $0.32 What if we’re out of nickels, change for $0.32? l Greedy doesn’t always work, but it does sometimes l Weighted shortest path algorithm is Dijkstra’s algorithm, greedy and uses priority queue

Compsci 100, Spring Edsger Dijkstra l Turing Award, 1972 l Operating systems and concurrency l Algol-60 programming language l Goto considered harmful l Shortest path algorithm l Structured programming “Program testing can show the presence of bugs, but never their absence” l A Discipline of programming “For the absence of a bibliography I offer neither explanation nor apology”

Compsci 100, Spring Dijkstra’s Shortest Path Algorithm l Similar to breadth first search, but uses a priority queue instead of a queue. Code below is for breadth first search (distance[] replaces set) Vertex cur = q.remove(); for(Vertex v : adjacent(cur)){ if (!visited.contains(v)){ // if distance[v] == INFINITY visited.add(v); // distance[v] = distance[cur]+1 q.add(v); } l Dijkstra: Find minimal unvisited node, recalculate costs through node Vertex cur = pq.remove(); for(Vertex v : adjacent(cur)) if (distance[cur] + graph.weight(cur,v) < distance[v]) { distance[v] = distance[cur] + graph.weight(cur,v); pq.add(v); }

Compsci 100, Spring Shortest paths, more details l Single-source shortest path  Start at some vertex S  Find shortest path to every reachable vertex from S l A set of vertices is processed  Initially just S is processed  Each pass processes a vertex After each pass, shortest path from S to any vertex using just vertices from processed set (except for last vertex) is always known l Next processed vertex is closest to S still needing processing SAB CE process B SAB CE E 7 7 S A B C process C E 7 7 S A B C

Compsci 100, Spring Dijkstra’s algorithm works (greedily) l Choosing minimal unseen vertex to process leads to shortest paths Vertex cur = pq.remove(); for(Vertex v : adjacent(cur)) if (distance[cur]+graph.weight(cur,v) < distance[v]){ distance[v] = distance[cur] + graph.weight(cur,v); pq.add(v); } l We always know shortest path through processed vertices  When we choose w, there can’t be a shorter path to w than distance[w] – it would go through processed u, then we would have chosen u instead of w

Compsci 100, Spring Greedy Algorithms l A greedy algorithm makes a locally optimal decision that leads to a globally optimal solution  Huffman: choose two nodes with minimal weight, combine Leads to optimal coding, optimal Huffman tree  Making change with American coins: choose largest coin possible as many times as possible Change for $0.63, change for $0.32 What if we’re out of nickels, change for $0.32? l Greedy doesn’t always work, but it does sometimes l Weighted shortest path algorithm is Dijkstra’s algorithm, greedy and uses priority queue

Compsci 100, Spring Shafi Goldwasser l RCS professor of computer science at MIT  Twice Godel Prize winner  Grace Murray Hopper Award  National Academy  Co-inventor of zero-knowledge proof protocols How do you convince someone that you know something without revealing the knowledge? l Consider card readers for dorms  Access without tracking Work on what you like, what feels right, I now of no other way to end up doing creative work