Graphs - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Graphs

Description:

Definition A directed graph is a pair G = (V, E) ... Set of edges is a subset of Cartesian product VxV of a set of vertices i.e. ... Example1 ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 23
Provided by: IRE62
Category:
Tags: example1 | graphs

less

Transcript and Presenter's Notes

Title: Graphs


1
Graphs
  • Irena Pevac
  • CS501

2
Graphs Set of nodes Set of edges
3
Directed Graphs
  • Definition A directed graph is a pair G (V,
    E),
  • where V v1, v2, ..., vn is a set of vertices
    or nodes, and a set of directed edges (also
    called arcs) E ? VxV .
  • Set of edges is a subset of Cartesian product VxV
    of a set of vertices i.e.
  • E ? (x,y) x in V, y in V

4
Example of Directed Graph
  • Example G (V, E), V 1, 2, 3, 4 and E
    (1,2), (2,3), (3,4), (1,3)

5
Undirected Graphs
  • Definition An undirected graph is a pair G(V,
    E), where V v1, v2, ..., vn is a set of
    vertices, and E is set of undirected edges or
    lines connecting the nodes. .
  • Set of edges is a subset of a set of all two
    element sets over the set of vertices i.e.
  • E ? x,y x,y in V

6
Example of Undirected Graph
  • Example G (V, E), V 1, 2, 3, 4 and E
    1,2, 2,3, 3,4, 1,3

7
Complete Graph
  • Definition Graph G (V, E) with all possible
    edges present (i.e. E VxV) is called a complete
    graph.
  • Example
  • E1,2,3,4
  • V1,2, 1,3,
  • 1,4,2,3,
  • 2,4,3,4

8
Labeled Graphs
  • Directed or undirected graphs can have labels or
    weights associated with edges.
  • Example1
  • Vertices may be towns, edges are road connections
    between the towns and labels associated with
    edges may represent shortest road traveling
    distance among towns.
  • Example 2
  • Vertices may be towns, edges represnt direct
    flights between towns and labels may represent
    cost of the flight.

9
Definitions
  • A graph G is subgraph of a graph G(V, E) if G
    (V, E), and V? V and E? E.
  • A graph with a small number of edges present (
    ?E? lt ?V? log ?V?) is
  • called a sparse graph. ?E? denotes the
    cardinality of E.
  • A graph that is not sparse is called a dense
    graph.

10
Labels for Vertices
  • Vertices also may have labels.
  • The names of vertices must be distinct but two or
    more vertices may have the same label.
  • When each vertex has different label we usually
    use labels as names.

11
Path
  • A path in a directed graph is a list of nodes
    (n1,n2,n3,nk) where ni is in V each consecutive
    two ni,ni1 are connected with with an arc.
  • A length of a path is number of arcs along the
    path.
  • Any node v by itself is a path of length zero
    from v to v. This path has no arcs.

12
Cycle
  • A cycle in a directed graph is a path of length
    one or more that begins and ends at the same
    node.
  • The length of the cycle is the length of the
    path.
  • Trivial path (v) of length 0 is not a cycle.
  • A path (v,v) consisting of a single arc v-gtv is a
    cycle of length 1.

13
Adjacent Vertices
  • Let G (V, E), and let x, y be two vertices
    from V. If x,y belongs to E we say that x and
    y are adjacent. Also we say that x and y are
    called incident to the edge x, y.

14
Adjacency Matrix
  • Graph G(V,E) can be represented with adjacency
    matrix by creating a two-dimensional array x, in
    which the value xuv is true iff (u,v) is an
    edge in E.
  • For undirected graphs adjacency matrix is
    symmetric.

15
Adjacency List
  • Graph G(V,E) can be represented with adjacency
    list by creating an array x with ?V? items. Each
    value xu has linked list of items
    correcponding to nodes adjacent to u.

16
Example
  • Let G (V,E) V a, b, c, d and
  • E a,b, c,d, b,c, a,c.

17
Adjacency Matrix
  • In adjacency matrix we use 0 for false and 1 for
    true.

18
Adjacency List
19
Representing Labeled Graphs
  • Labeled graph has labels or weights on its arcs
    (if directed) or on its edges (if undirected.
  • In adjacency matrix we can replace the 1 that
    represents the presence of an arc by its label.
    It is necessary to have a special value (that is
    different than any label) to be matrix entry
    indicating the absence of an arc.

20
Example Labeled Graph
21
Adjacency Matrix
  • In adjacency matrix we use -1 for absence of the
    arc and label on the arc when arc is present.

22
Adjacency List for Labeled Graph
Write a Comment
User Comments (0)
About PowerShow.com