233-234233-234 Sedgewick & Wayne (2004); Chazelle (2005) Sedgewick & Wayne (2004); Chazelle (2005)

Slides:



Advertisements
Similar presentations
CS203 Lecture 15.
Advertisements

Depth-First Search1 Part-H2 Depth-First Search DB A C E.
Minimum Spanning Tree Sarah Brubaker Tuesday 4/22/8.
Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
Analysis of Algorithms Depth First Search. Graph A representation of set of objects Pairs of objects are connected Interconnected objects are called “vertices.
Graph Searching CSE 373 Data Structures Lecture 20.
1 Undirected Breadth First Search F A BCG DE H Source:
Graphs By JJ Shepherd. Introduction Graphs are simply trees with looser restrictions – You can have cycles Historically hard to deal with in computers.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Using nextAdjacent() To list all vertices connected to a vertex u in graph G we can use the following loop: for (int v=G.nextAdjacent(u,-1); v>=0; v=G.nextAdjacent(u,v))
Sedgewick & Wayne (2004); Chazelle (2005) Sedgewick & Wayne (2004); Chazelle (2005)
1 Undirected Depth First Search Adjacency Lists A: F C B G B: A C: A D: F E E: G F D F: A E D: G: E A: H: I: I: H: F A BCG DE HI.
1 Data Structures and Algorithms Graphs I: Representation and Search Gal A. Kaminka Computer Science Department.
CSE 780 Algorithms Advanced Algorithms Graph Algorithms Representations BFS.
Sedgewick & Wayne (2004); Chazelle (2005) Sedgewick & Wayne (2004); Chazelle (2005)
1 public class Graph { private int V; private Node[] adj; private int[] degree; private static class Node { int vertex; Node next; Node(int v, Node next)
Depth-First Search Lecture 24 COMP171 Fall Graph / Slide 2 Depth-First Search (DFS) * DFS is another popular graph search strategy n Idea is similar.
Graphs CS 400/600 – Data Structures. Graphs2 Graphs  Used to represent all kinds of problems Networks and routing State diagrams Flow and capacity.
Graph Search Computing 2 COMP s1. P ROBLEMS ON G RAPHS What kinds of problems do we want to solve on/via graphs? Is there a simple path from A to.
1 Graphs and Search Trees Instructor: Mainak Chaudhuri
Computer Science 112 Fundamentals of Programming II Introduction to Graphs.
Nattee Niparnan. Graph  A pair G = (V,E)  V = set of vertices (node)  E = set of edges (pairs of vertices)  V = (1,2,3,4,5,6,7)  E = ((1,2),(2,3),(3,5),(1,4),(4,
CS200 Algorithms and Data StructuresColorado State University Part 10. Graphs CS 200 Algorithms and Data Structures 1.
Lecture 14 Graph Representations. Graph Representation – How do we represent a graph internally? – Two ways adjacency matrix list – Adjacency Matrix For.
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.
Graphs – Part II CS 367 – Introduction to Data Structures.
Trees, Binary Search Trees, Balanced Trees, Graphs Graph Fundamentals Telerik Algo Academy
COSC 2007 Data Structures II
The Graph Data Structure Mugurel Ionu Andreica Spring 2012.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: Graphs Data Structures.
Graph Searching CSIT 402 Data Structures II. 2 Graph Searching Methodology Depth-First Search (DFS) Depth-First Search (DFS) ›Searches down one path as.
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
GRAPH ALGORITHM. Graph A pair G = (V,E) – V = set of vertices (node) – E = set of edges (pairs of vertices) V = (1,2,3,4,5,6,7) E = ( (1,2),(2,3),(3,5),(1,4),(4,5),(6,7)
1 A Case Study: Percolation Percolation. Pour liquid on top of some porous material. Will liquid reach the bottom? Applications. [ chemistry, materials.
abstract data types built on other ADTs
Nattee Niparnan. Graph  A pair G = (V,E)  V = set of vertices (node)  E = set of edges (pairs of vertices)  V = (1,2,3,4,5,6,7)  E = ((1,2),(2,3),(3,5),(1,4),(4,
Undirected Single-Source Shortest Paths with Positive Integer Weights in Linear Time MIKKEL THORUP 1999 Journal of ACM.
Data Structures & Algorithm Analysis lec(8):Graph T. Souad alonazi
Graphs Chapter 15 introduces graphs which are probably the most general and commonly-used data structure. This lecture introduces heaps, which are used.
Undirected versus Directed Graphs
Lecture 11 Graph Algorithms
CSE 2331/5331 Topic 9: Basic Graph Alg.
CC 215 Data Structures Graph Searching
Depth-First Search.
Data Structures and Algorithms for Information Processing
Graphs.
Depth-First Search D B A C E Depth-First Search Depth-First Search
Graphs Representation, BFS, DFS
Search Related Algorithms
Graph Representation (23.1/22.1)
Elementary Graph Algorithms
Depth-First Search D B A C E Depth-First Search Depth-First Search
Undirected Depth First Search
Chapter 11 Graphs.
Graphs Part 2 Adjacency Matrix
Depth-First Search Graph Traversals Depth-First Search DFS.
CSE 373 Data Structures Lecture 16
Depth-First Search D B A C E Depth-First Search Depth-First Search
Undirected Depth First Search
COMP171 Depth-First Search.
Undirected Depth First Search
Depth-First Search CSE 2011 Winter April 2019.
Graph Implementation.
Graph Traversal Lecture 18 CS 2110 — Spring 2019.
Depth-First Search CSE 2011 Winter April 2019.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Data structure for graph algorithms: Adjacent list, Adjacent matrix
Undirected Depth First Search
Lecture 10 Graph Algorithms
Presentation transcript:

Sedgewick & Wayne (2004); Chazelle (2005) Sedgewick & Wayne (2004); Chazelle (2005)

computation theory experimentation

computation theory experimentation

computation theory experimentation

computation theory experimentation Moore’s Law

No Moore’s Law there ! there ! No Moore’s Law there ! there ! Inverse Moore’s Law?

1. Power of algorithms

2. Duality: data & programs 3. Recursion 1. Power of algorithms

A program in C /**/char q='"',*a="*//**/char q='%c',*a=%c%s%c*/};)b(stup;]d[b=]d-472 [b)--d(elihw;)q,a,q,q,2+a,b(ftnirps;)b(stup{)(niam;731=d tni;]572 [b,",b[275];int d=137;main(){puts(b);sprintf(b,a+2,q,q,a,q);while(d--) b[274-d]=b[d];puts(b);}/*c%s%c%=a*,'c%'=q rahc/**//*"=a*,'"'=q rahc/**/ (By Dan Hoey)

char*s="char*s=%c%s%c;void main(){ printf(s,34,s,34);}";void main(){printf(s,34,s,34);} A program in C

'; printf ($s,39,$s,39); ?> A program in php

$s="$s=%c%s%c;printf$s,34,$s,34;";printf$s,34,$s,34; A program in perl

l='l=%s;print l%`l`';print l%`l` A program in python

class S{public static void main(String[]a){String s="class S{ public static void main(String[]a){String s=;char c=34; System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}}"; char c=34; System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}} A program in Java Output = ? class S{public static void main(String[]a){String s="class S{ public static void main(String[]a){String s=;char c=34; System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}}"; char c=34; System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}}

Why does Schroedinger hate cats? Print next statement twice Output = ? Why does Schroedinger hate cats? A B AB  BB

Print next statement twice Output = ? Set B=A AA  AA Print next statement twice

string of symbols datacommand

Rogozhin (1996) : 24 states input data output data program data Babbage (1820)

Print next statement twice Why does Schroedinger hate cats? Print next statement twice

duality recursion

duality + recursion Self-reproduction =

duality recursion gene - protein dble-stranded

What is the difference between classical math and computer science ?

Jos Leys

Protein Interaction Network Jeong et al

Adjacency matrix

Adjacency lists

public class Graph { private int V; private Node[] adj; private int[] degree; private static class Node { int vertex; Node next; Node(int v, Node next) { this.vertex = v; this.next = next; } Adjacency List Implementation vertex next Node

public class Graph { private int V; private Node[] adj; private int[] degree; private static class Node { int vertex; Node next; Node(int v, Node next) { this.vertex = v; this.next = next; } public Graph(int V) { this.V = V; adj = new Node[V]; degree = new int[V]; } Adjacency List Implementation graph on V vertices with no edges Node

public int V() { return V; } public void addEdge(int v, int w) { adj[v] = new Node(w, adj[v]); adj[w] = new Node(v, adj[w]); degree[v]++; degree[w]++; } Adjacency List Implementation # vertices add w to v's adjacency list add v to w's adjacency list v w x z y

public int V() { return V; } public void addEdge(int v, int w) { adj[v] = new Node(w, adj[v]); adj[w] = new Node(v, adj[w]); degree[v]++; degree[w]++; } Adjacency List Implementation # vertices add w to v's adjacency list add v to w's adjacency list v w x z y

public int V() { return V; } public void addEdge(int v, int w) { adj[v] = new Node(w, adj[v]); adj[w] = new Node(v, adj[w]); degree[v]++; degree[w]++; } Adjacency List Implementation # vertices add w to v's adjacency list add v to w's adjacency list v w x z y

public int V() { return V; } public void addEdge(int v, int w) { adj[v] = new Node(w, adj[v]); adj[w] = new Node(v, adj[w]); degree[v]++; degree[w]++; } Adjacency List Implementation # vertices add w to v's adjacency list add v to w's adjacency list v w x z y w

public int V() { return V; } public void addEdge(int v, int w) { adj[v] = new Node(w, adj[v]); adj[w] = new Node(v, adj[w]); degree[v]++; degree[w]++; } Adjacency List Implementation # vertices add w to v's adjacency list add v to w's adjacency list v w x z y w

public int V() { return V; } public void addEdge(int v, int w) { adj[v] = new Node(w, adj[v]); adj[w] = new Node(v, adj[w]); degree[v]++; degree[w]++; } Adjacency List Implementation # vertices add w to v's adjacency list add v to w's adjacency list v w x z y w

public int V() { return V; } public void addEdge(int v, int w) { adj[v] = new Node(w, adj[v]); adj[w] = new Node(v, adj[w]); degree[v]++; degree[w]++; } Adjacency List Implementation # vertices add w to v's adjacency list add v to w's adjacency list v w z y w x

public int[] neighbors(int v) { int[] neighbors = new int[degree[v]]; int i = 0; for (Node x = adj[v]; x != null; x = x.next) neighbors[i++] = x.vertex; return neighbors; } Return list of neighbors of v as an array d c a b v neighbors adj null a b c d i= 0i= 1 i= 2i= 3 xx

1. Birds eat the bread crumbs 2. They don’t random walk DFS/BFS Hansel & Gretel

Diffusion equation

Normal distribution Random walk

With bread crumbs one can find exit in time proportional to V+E DFS/BFS Hansel & Gretel

Undirected Depth First Search Adjacency Lists A: F C B G B: A C: A D: F E E: G F D F: A E D: G: E A: H: I: I: H: F A BCG DE HI

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack F newly discovered

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) A already marked

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) E newly discovered E

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) visit(E) (E, G) (E, F) (E, D) G newly discovered G

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) visit(E) (E, G) (E, F) (E, D) visit(G) (G, E) (G, A) E already marked

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) visit(E) (E, G) (E, F) (E, D) visit(G) (G, E) (G, A) A already marked

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) visit(E) (E, G) (E, F) (E, D) visit(G) (G, E) (G, A) Finished G

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) visit(E) (E, G) (E, F) (E, D) F already marked

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) visit(E) (E, G) (E, F) (E, D) D newly discovered D

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) visit(E) (E, G) (E, F) (E, D) visit(D) (D, F) (D, E) F already marked

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) visit(E) (E, G) (E, F) (E, D) visit(D) (D, F) (D, E) E already marked

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) visit(E) (E, G) (E, F) (E, D) visit(D) (D, F) (D, E) Finished D

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) visit(E) (E, G) (E, F) (E, D) Finished E

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) D already marked

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(F) (F, A) (F, E) (F, D) Finished F

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack C newly discovered C

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(C) (C, A) A already marked

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(C) (C, A) Finished C

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack B newly discovered B

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(B) (B, A) A already marked

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack visit(B) (B, A) Finished B

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack G already finished

visit(A) (A, F) (A, C) (A, B) (A, G) Undirected Depth First Search F A BCG DE HI Stack Finished A

Undirected Depth First Search F A BCG DE HI Stack

Undirected Depth First Search F A BCG DE HI Stack visit(H) (H, I) I newly discovered I

Undirected Depth First Search F A BCG DE HI Stack visit(H) (H, I) visit(I) (I, H) H already marked

Undirected Depth First Search F A BCG DE HI Stack visit(H) (H, I) visit(I) (I, H) Finished I

Undirected Depth First Search F A BCG DE HI Stack visit(H) (H, I) FinishedH

Undirected Depth First Search F A BCG DE HI Stack

public class DFSearcher { private static int UNMARKED = -1; private int[] cc; private int components; public DFSearcher(Graph G) { // next slide } public int component(int v) { return cc[v]; } public int components() { return components; } Connected components of a graph G. * For each vertex, give id number corresponding to component.

public DFSearcher(Graph G) { components = 0; cc = new int[G.V()]; for (int v = 0; v < G.V(); v++) cc[v] = UNMARKED; for (int v = 0; v < G.V(); v++) { if (cc[v] == UNMARKED) { dfs(G, v); components++; } private void dfs(Graph G, int v) { cc[v] = components; int[] neighbors = G.neighbors(v); for (int i = 0; i < neighbors.length; i++) { int w = neighbors[i]; if (cc[w] == UNMARKED) dfs(G, w); } v c b d a b a c d w 0

Is graph connected?

Depth First Search