Advertisement! CSE 528 Computational Neuroscience now open to - - PDF document

advertisement
SMART_READER_LITE
LIVE PREVIEW

Advertisement! CSE 528 Computational Neuroscience now open to - - PDF document

Last Course Topic: Graphs & Trees Motivation for Graphs Definition Directed and undirected graphs Representing Graphs Paths, Circuits, and Trees Famous Graph Problems Covered in Chapters 9 and 10 in the text (we will


slide-1
SLIDE 1

1

  • R. Rao, CSE 311

Last Course Topic: Graphs & Trees

 Motivation for Graphs  Definition

 Directed and undirected graphs

 Representing Graphs  Paths, Circuits, and Trees  Famous Graph Problems  Covered in Chapters 9 and 10 in the text (we will cover

mainly 9.1 and 10.1; you can browse the other sections)

Based on Rosen and S. Wolfman 2

  • R. Rao, CSE 311

Advertisement!

 CSE 528 Computational Neuroscience now open to

undergraduates

 How does the brain work?  How does it learn?  How does it predict?  How does it take action?  Can computer science help us understand the brain?  Prerequisites: elementary calculus, linear algebra, and basic

probability/statistics

slide-2
SLIDE 2

3

  • R. Rao, CSE 311

What are graphs? (Take 1)

 Yes, this is a graph….  But we are interested in a different kind of “graph”

4

  • R. Rao, CSE 311

Course Prerequisites for CSE at UW

Nodes = courses Directed edge = prerequisite

332 143 142 312 311 331 351 352 333

slide-3
SLIDE 3

5

  • R. Rao, CSE 311

Representing a Maze or Floor Plan of a House

F B

Nodes = rooms Edge = door or passage

F B

6

  • R. Rao, CSE 311

Representing Electrical Circuits

Nodes = battery, switch, resistor, etc. Edges = connections Battery Switch Resistor

slide-4
SLIDE 4

7

  • R. Rao, CSE 311

Representing Expressions in Compilers

x1=q+y*z x2=y*z-q

Naive: common subexpression eliminated: y z *

  • q

+ q * x1 x2 y z

  • q

+ q * x1 x2

Nodes = symbols/operators Edges = relationships

y*z calculated twice

8

  • R. Rao, CSE 311

Dependency structure of statements

slide-5
SLIDE 5

9

  • R. Rao, CSE 311

Data Centers and Connections

10

  • R. Rao, CSE 311

Data Centers with Multiple Connections

slide-6
SLIDE 6

11

  • R. Rao, CSE 311

Data Centers with Diagnostic Connections

12

  • R. Rao, CSE 311

Network with One-Way Links

slide-7
SLIDE 7

13

  • R. Rao, CSE 311

People and Tasks

14

  • R. Rao, CSE 311

Competition between Species

slide-8
SLIDE 8

15

  • R. Rao, CSE 311

Facebook Friends

16

  • R. Rao, CSE 311

Soap Opera Relationships

Victor Ashley Brad Wayne Trisha Peter

slide-9
SLIDE 9

17

  • R. Rao, CSE 311

Six Degrees of Separation from Kevin Bacon

Apollo 13 Toy Story Tom Hanks Gary Sinise Robin Wright Wallace Shawn Cary Elwes Laurie Metcalf Rosanna Arquette Cheech Marin

18

  • R. Rao, CSE 311

Information Transmission in a Computer Network

Seattle New York L.A. Tokyo Sydney Seoul Nodes = computers Weights on edges = transmission rates 128 140 181 30 16 56

slide-10
SLIDE 10

19

  • R. Rao, CSE 311

Traffic Flow on Highways

Nodes = cities Weights on edges = # vehicles on connecting highway

UW

20

  • R. Rao, CSE 311

Flight times between cities

slide-11
SLIDE 11

21

  • R. Rao, CSE 311

Fares between cities

22

  • R. Rao, CSE 311

Mileage between cities

slide-12
SLIDE 12

23

  • R. Rao, CSE 311

Bayesian Networks (Nodes + Edges + Probabilities)

24

  • R. Rao, CSE 311

Bayesian Network for Gene Interactions

slide-13
SLIDE 13

25

  • R. Rao, CSE 311

Bayesian Network for Medical Diagnosis

26

  • R. Rao, CSE 311

Image Analysis (“Markov Random Field”)

Object Background Image Pixels

slide-14
SLIDE 14

27

  • R. Rao, CSE 311

Graphs: Definition

 A graph is simply a collection of nodes plus edges

 Linked lists, trees, and heaps are all special cases of graphs

 The nodes are known as vertices (node = “vertex”)  Formal Definition: A graph G = (V, E) where

 V is a set of vertices or nodes  E is a set of edges that connect vertices

28

  • R. Rao, CSE 311

Graphs: An Example

 Here is a graph G = (V, E)

 Each edge is a pair (v1, v2), where v1, v2 are vertices in V V = {A, B, C, D, E, F} E = {(A,B), (A,D), (B,C), (C,D), (C,E), (D,E)} A B C F D E

slide-15
SLIDE 15

29

  • R. Rao, CSE 311

Directed versus Undirected Graphs

 If order of edge pairs (v1, v2) matters, graph is directed (also

called a digraph): (v1, v2)  (v2, v1)

 If order of edge pairs (v1, v2) does not matter, graph is called

an undirected graph: in this case, (v1, v2) = (v2, v1) so the edge = {v1, v2} v1 v2 v1 v2

30

  • R. Rao, CSE 311

 Degree of a vertex in an undirected graph = number of edges

incident on the vertex

 In-Degree/Out-degree in a digraph = number of edges

entering/exiting a vertex

Degree, In-Degree, Out-Degree

Deg(1) = 2 Deg(4) = 3 In-Deg(2) = 2 Out-Deg(2) = 1 In-Deg(4)=Out-Deg(4)=2

slide-16
SLIDE 16

31

  • R. Rao, CSE 311

Graph Representations

There are two ways of representing graphs:

  • The adjacency matrix representation
  • The adjacency list representation

32

  • R. Rao, CSE 311

Graph Representation: Adjacency Matrix

The adjacency matrix representation:

A B C F D E A B C D E F 0 1 0 1 0 0 1 0 1 0 0 0 0 1 0 1 1 0 1 0 1 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 M(v, w) = 1 if (v, w) is in E 0 otherwise A B C D E F

slide-17
SLIDE 17

33

  • R. Rao, CSE 311

The adjacency list representation: For each v in V,

B D B D C A C E D E A C

L(v) = list of w such that (v, w) is in E

A B C F D E

Graph Representation: Adjacency List

A B C D E F (A,B) (A,D)

34

  • R. Rao, CSE 311

B D E D C

Adjacency List for a Digraph

A B C D E F A B C F D E E Digraph Adjacency List

slide-18
SLIDE 18

35

  • R. Rao, CSE 311

 Path of length k from vertex u to vertex u' in G = (V, E) =

sequence of vertices <v0, v1, ..., vk> where v0 = u, vk = u', and (vi -1, vi)  E for i = 1, 2, ..., k.

Paths in Graphs

A path from a to c <a, b, c> Another path: <a, e, b, f, e, b, c>

36

  • R. Rao, CSE 311

 Simple Path: Path that does not repeat an edge  Circuit: Path that begins and ends at the same vertex

Simple Paths and Circuits

A simple path from a to c <a, b, c> Not a simple path: <a, e, b, f, e, b, c> Circuit: <a,b,c, f, b, a> Simple circuit: <a,b,c,f,e,a> Simple circuit visiting all vertices: <a,b,c,f,e,d,a>

slide-19
SLIDE 19

37

  • R. Rao, CSE 311

 An undirected graph is connected iff there is a path between

every pair of vertices

 A directed graph is (weakly) connected iff the underlying

undirected graph is connected

Connected Graphs

Connected Not connected Connected

38

  • R. Rao, CSE 311

 A tree is a connected graph with no circuits

Trees

Tree Tree Not a tree Not a tree

slide-20
SLIDE 20

39

  • R. Rao, CSE 311

Examples of Trees: Folders and file system

40

  • R. Rao, CSE 311

Example: Connecting Multi-Processors

E.g., Multiplying 8 large numbers in 3 steps

slide-21
SLIDE 21

41

  • R. Rao, CSE 311

Binary Search Trees

> 31 < 31

42

  • R. Rao, CSE 311

Game Trees

Which move do you choose? (a “X”)

slide-22
SLIDE 22

43

  • R. Rao, CSE 311

Pray tell, how does a prince represent his royal family tree?

44

  • R. Rao, CSE 311
slide-23
SLIDE 23

45

  • R. Rao, CSE 311

Famous Graph Problems: Topological Sort

Problem: Find an order in which all these courses can be taken. Example: 142, 143, 331, 311, 312, 332, 351, 352, 333 To take a course, all its prerequisites must be taken first Graph of course prerequisites

332 143 142 312 311 331 351 352 333

46

  • R. Rao, CSE 311

 Find a circuit going through every edge exactly once.

Famous Graph Problems: Euler Circuits

abedcea No Euler circuit No Euler circuit

(An Euler path exists though)

Theorem: For Euler circuit to exist, every vertex must have even degree (Why? If entering vertex, must exit)

 Fast algorithm for checking if Euler circuit exists

slide-24
SLIDE 24

47

  • R. Rao, CSE 311

 Find a circuit passing through every vertex exactly

  • nce.

Hamiltonian Circuit Problem

San Francisco, Chicago, Boston, New York, Miami, Atlanta, Denver, LA, San Francisco

48

  • R. Rao, CSE 311

 Find a circuit in G = (V,E) passing through every

vertex exactly once.

 Naïve algorithm:  Try all permutations of the vertices  Check to see if any permutation is a valid Hamiltonian circuit in the graph.  There are |V|! permutations  running time is >

exponential in size of input.

Hamiltonian Circuit Problem

Can show this is an “NP-Complete” Problem: Fast algorithm unlikely to exist!! (More on this in CSE 312)

slide-25
SLIDE 25

49

  • R. Rao, CSE 311

Next Class: Final Review!