Computer Science II - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Computer Science II

Description:

An acyclic graph ... A graph can be represented by an adjacency matrix. For each edge (vi,vj) ... graph, how would you represent it as an adjacency matrix? ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 9
Provided by: joe49
Category:
Tags: an | computer | science

less

Transcript and Presenter's Notes

Title: Computer Science II


1
Computer Science II
  • Graphs

2
What is a Directed Graph?
  • An ordered pair G (V,E)
  • V is a finite, non-empty set of vertices (nodes)
  • E is a finite set of ordered pairs, which are the
    edges (arcs) of G
  • E ? V ? V

3
GraphTerminology
  • Vertex b is adjacent to vertex a
  • Edge emanates from vertex a
  • A(a) is the set of edges emanating from vertex a
  • A(a) is the out-degree of vertex a
  • Edge is incident on vertex b
  • I(b) is the set of edges incident on vertex b
  • I(b) is the in-degree of vertex b

4
Paths
  • A path in a directed graph G (V,E) is a
    non-empty sequence of verticesP
    v1,v2,...,vkwhere vi ? V for 1 ? i ? ksuch
    that (vi,vi1) ? E for 1 ? i lt k
  • The length of the path P is k-1

5
PathTerminology
  • Vertex b is the successor of Vertex a
  • Vertex b is the predecessor of Vertex c
  • Simple paths have no repeated vertices
  • A cycle is where v1 vk

6
More on graphs
  • An acyclic graph has no cycles
  • Undirected graphs are similar to directed graphs
    except that E is a set of unordered pairs

7
Representing graphs
  • A graph can be represented by an adjacency matrix
  • For each edge (vi,vj) ? E, M(i,j) 1
  • All other positions in the matrix are set to 0
  • Sparse matrices (many vertices, few edges) can be
    implemented as linked list of linked lists

8
Questions?
  • Given the following graph, how would you
    represent it as an adjacency matrix?
  • How would you determine if there is a path from
    vertex a to vertex d?

a
b
d
c
Write a Comment
User Comments (0)
About PowerShow.com