lecture 5 cse 331. graphs problem statement algorithm problem definition “implementation”...

18
Lecture 5 CSE 331

Upload: julius-parrish

Post on 06-Jan-2018

215 views

Category:

Documents


0 download

DESCRIPTION

Graphs Representation of relationships between pairs of entities/elements Entities: News hosts Relationship: Mention in other’s program Entities: News hosts Relationship: Mention in other’s program Vertex/Node Edge

TRANSCRIPT

Page 1: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

Lecture 5

CSE 331

Page 2: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

GraphsProblem Statement

Algorithm

Problem Definition

“Implementation”

Analysis

A generic tool to abstract out

problems

Page 3: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

GraphsRepresentation of relationships between pairs of entities/elements

Entities: News hosts

Relationship: Mention in other’s program

Vertex/Node

Edge

Page 4: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

Graphs are omnipresentAirline Route maps

Page 5: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

What does this graph represent?

Internet

Page 6: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

And this one?Math articles on Wikipedia

Page 7: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

And this one?

Page 8: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

Basic Graph definitionsFormally define everything

http://imgs.xkcd.com/comics/geeks_and_nerds.png

Page 9: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

Paths

Sequence of vertices connected by edges

, , ,

Path length 3

,

Connected

Page 10: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

Connectivity

u and w are connected iff there is a path between them

A graph is connected iff all pairs of vertices are connected

Page 11: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

Connected Graphs

Every pair of vertices has a path between them

Page 12: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

Cycles

Sequence of k vertices connected by edges, first k-1 are distinct

, , ,

Page 13: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

TreeConnected undirected graph with no cycles

Page 14: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

Rooted Tree

Page 15: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

A rooted tree

Pick any vertex as root

Let the rest of the tree hang under “gravity”

How many rooted trees

can an n vertex tree

have?

SG’s parent=AC

AC’s child=SG

Page 16: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

Prove n vertex tree has n-1 edges

Page 17: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

Prove n vertex tree has n-1 edges

• Pick an arbitrary node to be the root• Image every edge is directed towards the root• Every non-root node has 1 outgoing edge• There are n-1 non-root nodes• There are n-1 edges

1

2 3

4 5 7 8

6

Page 18: Lecture 5 CSE 331. Graphs Problem Statement Algorithm Problem Definition “Implementation” Analysis A generic tool to abstract out problems

Directed graphs

Model asymmetric relationships

Precedence relationships

u needs to be done before w means (u,w) edge