Today - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Today

Description:

Today s Material: Graphs Definition Graph, Digraph Representation Adjacency Matrix Adjacency List More Definitions & Properties Path, Cycle?, relationship between ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 10
Provided by: Cune4
Category:

less

Transcript and Presenter's Notes

Title: Today


1
Todays Material Graphs
  • Definition
  • Graph, Digraph
  • Representation
  • Adjacency Matrix
  • Adjacency List
  • More Definitions Properties
  • Path, Cycle?, relationship between vertices
    edges
  • Sparse graph, Dense Graph?

2
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 is a pair (V, E)
    where
  • V is a set of vertices or nodes
  • E is a set of edges that connect vertices

3
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)

C
B
F
A
D
E
4
Directed vs Undirected Graphs
  • If the order of edge pairs (v1, v2) matters, the
    graph is directed (also called a digraph) (v1,
    v2) ? (v2, v1)

v2
v1
  • If the order of edge pairs (v1, v2) does not
    matter, the graph is undirected (v1, v2) (v2,
    v1)

5
Weighted Graphs An Example
  • Graph edges may have weights on them
  • The meaning of the weight is application
    dependent
  • E.g., Distance between cities
  • Bandwidth between routers etc.

20
C
B
10
30
F
A
50
5
15
D
E
6
Graph Representations
  • Space and time are measured in terms of both
  • Number of vertices V n
  • Number of edges E e
  • There are two ways of representing graphs
  • The adjacency matrix representation
  • The adjacency list representation

7
Adjacency Matrix Representation
  • Adjacency matrix representation
  • 1 if (u, v) is in E
  • 0 otherwise

M(u, v)
A B C D E F
A 0 1 0 1 0 0
B 0 0 1 0 0 0
C 0 0 0 1 1 0
D 0 0 0 0 1 0
E 0 0 0 0 0 0
F 0 0 0 0 0 0
Space?
O(n2)
8
Adjacency Matrix Representation
  • Adjacency matrix repr. of a weighted graph
  • weight(u, v) if (u, v)
    is in E
  • 8 otherwise

M(u, v)
A B C D E F
A 8 10 8 5 8 8
B 8 8 20 8 8 8
C 8 8 8 30 50 8
D 8 8 8 8 15 8
E 8 8 8 8 8 8
F 8 8 8 8 8 8
20
10
30
50
5
15
9
Adjacency List Representation
  • Adjacency list representation For each v in V,
    L(v) list of w such that (v, w) is in E

A
B
C
D
E
F
na b2e O(ne)
Space?
Write a Comment
User Comments (0)
About PowerShow.com