Graphs and Sets - Data Structures - Lecture Slides, Slides of Data Structures and Algorithms

In the subject of the Data Structures, the key concept and the main points, which are very important in the context of the data structures are listed below:Graphs and Sets, Data Structure, Vertices, Set of Edges, Vertices, Applications, Schedules, Computer Networks, Circuits, Hypertext

Typology: Slides

2012/2013

Uploaded on 04/23/2013

saratey
saratey šŸ‡®šŸ‡³

4.3

(10)

86 documents

1 / 86

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 9
Graphs and Sets
Lecture 19
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56

Partial preview of the text

Download Graphs and Sets - Data Structures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

Chapter 9

Graphs and Sets

Lecture 19

What is a graph?

  • A data structure that consists of a set of

nodes ( vertices ) and a set of edges between the vertices.

  • The set of edges describes relationships

among the vertices.

1 2

3 4

Definitions

  • Graph: A data structure that consists of a set

of nodes and a set of edges that relate the nodes to each other

  • Vertex: A node in a graph
  • Edge (arc): A pair of vertices representing a

connection between two nodes in a graph

  • Undirected graph: A graph in which the edges

have no direction

  • Directed graph (digraph): A graph in which

each edge is directed from one vertex to another (or the same) vertex

Formally

  • a graph G is defined as follows:

G = (V,E)

where

  • V(G) is a finite, nonempty set of vertices
  • E(G) is a set of edges
    • written as pairs of vertices

A directed graph

A graph in which each edge is directed from one vertex to another (or the same) vertex

The order of vertices in E

is important for

directed graphs!!

A directed graph

Trees are special cases of graphs!

  • Path: A sequence of vertices that

connects two nodes in a graph

  • The length of a path is the number of

edges in the path.

e.g., a path from 1 to 4

1 2

3 4

<1, 2, 3, 4>

Graph terminology

Graph terminology

Complete graph: A graph in which every vertex

is directly connected to every other vertex

  • What is the number of edges E in a

complete directed graph with V vertices?

E=V * (V-1)

Graph terminology (cont.)

or O(V^2 )

A weighted graph

Weighted graph: A graph in which each edge carries a value

to node x?

from node x?

Adjacency Matrix for Flight Connections

Array-Based Implementation (cont.)

  • Memory required
    • O(V+V^2 )=O(V^2 )
  • Preferred when
    • The graph is dense: E = O(V^2 )
  • Advantage
    • Can quickly determine if there is an edge between two vertices
  • Disadvantage
    • Consumes significant memory for sparse large graphs

Adjacency List Representation of Graphs

to node x?

from node x?

Link-List-based Implementation (cont.)

  • Memory required
    • O(V + E)
  • Preferred when
    • for sparse graphs: E = O(V)
  • Disadvantage
    • No quick way to determine the vertices adjacent to a given vertex
  • Advantage
    • Can quickly determine the vertices adjacent from a given vertex

O(V) for sparse graphs since E=O(V) O(V^2 ) for dense graphs since E=O(V 2 )