Graphs Graphs Examples Definitions Implementation/Representation - - PowerPoint PPT Presentation

graphs graphs
SMART_READER_LITE
LIVE PREVIEW

Graphs Graphs Examples Definitions Implementation/Representation - - PowerPoint PPT Presentation

CS171 Introduction to Computer Science II Science II Graphs Graphs Examples Definitions Implementation/Representation of graphs Graphs Graphs: set of vertices connected pairwise by edges Interesting and useful structure


slide-1
SLIDE 1

CS171 Introduction to Computer Science II Science II

Graphs

slide-2
SLIDE 2

Graphs

Examples Definitions Implementation/Representation of graphs

slide-3
SLIDE 3

Graphs

Graphs: set of vertices connected pairwise by edges Interesting and useful structure Many practical applications Many practical applications

Maps Web content Schedules Social networks …

slide-4
SLIDE 4

Delta Airlines Domestic Routes

From Atlanta From

4/12/2012 4

Delta Airlines domestic routes From Memphis

ATL MEM LGA DEN LAX SEA DCA EWR DWF

slide-5
SLIDE 5

WWW

slide-6
SLIDE 6

Bow Tie Theory

slide-7
SLIDE 7

Facebook Friend Graph

slide-8
SLIDE 8
slide-9
SLIDE 9

Obesity study in social networks

slide-10
SLIDE 10

Course Prerequisite Graph

slide-11
SLIDE 11

Graphs

Undirected graphs

simple connections

Digraphs

each connection has a direction each connection has a direction

Edge-weighted graphs

each connection has an associated weight

Edge-weighted digraphs

each connection has both a direction and a weight

slide-12
SLIDE 12

Undirected Graphs

A graph is a set of vertices and a collection of edges that each connect a pair of vertices

slide-13
SLIDE 13
slide-14
SLIDE 14

Glossary

  • When there is an edge connecting two vertices, the vertices are

adjacent to one another and the edge is incident to both vertices

  • A self-loop is an edge that connects a vertex to itself
  • Two edges that connect the same pair of vertices are parallel
  • The degree of a vertex is the number of edges incident to the

vertex, with loops counted twice vertex, with loops counted twice

  • A subgraph is a subset of a graph’s edges (and associated vertices)

that constitutes a graph

slide-15
SLIDE 15

Glossary

  • A path in a graph is a sequence of vertices connected by edges

A simple path is one with no repeated vertices A cycle is a path with at least one edge whose first and last vertices are the same A simple cycle is a cycle with no repeated edges or vertices (except the first and last vertices) The length of a path is its number of edges The length of a path is its number of edges

  • One vertex is connected to another if there exists a path that

contains both of them

  • A graph is connected if there is a path from every vertex to every
  • ther vertex in the graph

A graph that is not connected consists of a set of connected components

  • An acyclic graph is a graph with no cycles.
slide-16
SLIDE 16
slide-17
SLIDE 17

Graphs

Examples Definitions Implementation/Representation of graphs

slide-18
SLIDE 18
slide-19
SLIDE 19

How to represent/implement a graph?

Space-efficient

Accommodate types of graphs that likely to encounter

Time-efficient Time-efficient

Add an edge If there is edge between v and w Iterate over vertices adjacent to v …

slide-20
SLIDE 20

Real-world graphs

Real-world graphs tend to be “sparse”

Huge number of vertices, small average vertex degree

slide-21
SLIDE 21

Representation Options

Edge list Adjacency matrix Adjacency lists

slide-22
SLIDE 22
slide-23
SLIDE 23
slide-24
SLIDE 24
slide-25
SLIDE 25
slide-26
SLIDE 26
slide-27
SLIDE 27
slide-28
SLIDE 28

Full implementation

http://algs4.cs.princeton.edu/41undirected/G raph.java.html

slide-29
SLIDE 29
slide-30
SLIDE 30