SlideShare a Scribd company logo
Graphs and
Spanning Trees
What is a graph?
Seattle
New York
L.A.
Tokyo
Sydney
Seoul 128
140
181
30
16
56
Graphs
graph: A data structure containing:
a set of vertices V, (sometimes called nodes)
a set of edges E, where an edge
represents a connection between 2 vertices.
Graph G = (V, E)
an edge is a pair (v, w) where v, w are in V
the graph at right:
V = {a, b, c, d}
E = {(a, c), (b, c), (b, d), (c, d)}
degree: number of edges touching a given vertex.
at right: a=1, b=2, c=3, d=2
a
c
b
d
Graph examples
For each, what are the vertices and what are the edges?
Web pages with links
Methods in a program that call each other
Road maps (e.g., Google maps)
Airline routes
Facebook friends
Course pre-requisites
Family trees
Paths through a maze
Paths
path: A path from vertex a to b is a sequence of edges that can be
followed starting from a to reach b.
can be represented as vertices visited, or edges taken
example, one path from V to Z: {b, h} or {V, X, Z}
What are two paths from U to Y?
path length: Number of vertices
or edges contained in the path.
neighbor or adjacent: Two vertices
connected directly by an edge.
example: V and X
X
U
V
W
Z
Y
a
c
b
e
d
f
g
h
Weighted graphs
weight: Cost associated with a given edge.
Some graphs have weighted edges, and some are unweighted.
Edges in an unweighted graph can be thought of as having equal weight (e.g. all 0, or all 1,
etc.)
Most graphs do not allow negative weights.
example: graph of airline flights, weighted by miles between cities:
ORD
PVD
MIA
DFW
SFO
LAX
LGA
HNL
Directed graphs
directed graph ("digraph"): One where edges are one-way
connections between vertices.
If graph is directed, a vertex has a separate in/out degree.
A digraph can be weighted or unweighted.
Is the graph below connected? Why or why not?
a
d
b
e
g
f
c
Spanning trees
 Suppose you have a connected undirected graph


Connected: every node is reachable from every other node.
Undirected: edges do not have an associated direction




...thus in the Mathematical field of graph theory, a spanning tree of the graph is
a connected sub-graph in which there are no cycles.
A Spanning tree for a graph has no cycles but still connects to every house.
If G is a connected graph with n vertices and m edges, spanning tree of G must
have n-1 edges, and no. of edges deleted from G to get a spanning tree must be
m-(n-1)=m-n+1.
A Graph may have many spanning trees; for instance the complete graph on
four vertices.
A connected,
undirected graph
Four of the spanning trees of the graph
8
Finding Spanning Trees
Spanning trees can be found in linear time by simply
performing breadth-first search or depth-first search.
These graph search algorithms are only dependent on
the number of vertices in the graph, so they are quite
fast.
Breadth-first search will use a queue to hold vertices to
explore later.
depth-first search will use a stack.
In either case, a spanning tree can be constructed by
connecting each vertex with the vertex that was used to
discover it.
Unfortunately, search algorithms are not well suited for
parallel or distributed computing, an area in which
spanning trees are popular.
There are, however, algorithms that are designed to find
spanning trees in a parallel setting.
4
Finding a spanning tree
 To find a spanning tree of a graph,
Pick an initial node and call it part of the spanning tree
do a search from the initial node:
each time you find a node that is not in the spanning tree, add to the
spanning tree both the new node and the edge you followed to get to it.
An undirected graph One possible
result of a BFS
starting from top
One possible
result of a DFS
starting from top
Properties of a spanning tree
There are a few general properties of spanning trees.
A connected graph can have more than one spanning tree.
All possible spanning trees for a graph G have the same number of edges and
vertices.
Spanning trees do not have any cycles.
Spanning trees are all minimally connected. That is, if any one edge is
removed, the spanning tree will no longer be connected.
Adding any edge to the spanning tree will create a cycle. So, a spanning tree is
maximally acyclic.
Spanning trees have |n|-1 edges, where |n| is the number of vertices
Spanningtreesppt
BFS
Spanningtreesppt
Spanningtreesppt

More Related Content

PPTX
Application Of Graph Data Structure
PPTX
Graph Basic In Data structure
PPT
PPTX
Graphs data Structure
PDF
Graph Data Structure
PPTX
Graph Theory
PPTX
Data Structure Graph DMZ #DMZone
PPTX
Graphs in Data Structure
Application Of Graph Data Structure
Graph Basic In Data structure
Graphs data Structure
Graph Data Structure
Graph Theory
Data Structure Graph DMZ #DMZone
Graphs in Data Structure

What's hot (20)

PDF
Graphs in datastructures
PPTX
Adjacency list
PPTX
Graph in data structure
PPTX
Graph representation
PPTX
Graph Data Structure
DOCX
Types of graphs
PPT
Chapter9 graph data structure
PPT
Graphs in Data Structure
PPT
Graph: Euler path and Euler circuit
PPTX
Data handling
PPTX
Data structures and algorithms lab7
PPT
Basics of graph
PPTX
Graphss
PPT
Applications of graphs
PPTX
Matrix representation of graph
PPTX
Data Structures - Lecture 10 [Graphs]
PPTX
Data handling class 8th
PPTX
Graph data structure and algorithms
PPTX
GRAPH THEORY
Graphs in datastructures
Adjacency list
Graph in data structure
Graph representation
Graph Data Structure
Types of graphs
Chapter9 graph data structure
Graphs in Data Structure
Graph: Euler path and Euler circuit
Data handling
Data structures and algorithms lab7
Basics of graph
Graphss
Applications of graphs
Matrix representation of graph
Data Structures - Lecture 10 [Graphs]
Data handling class 8th
Graph data structure and algorithms
GRAPH THEORY
Ad

Similar to Spanningtreesppt (20)

PPTX
Slides Chapter10.1 10.2
PPTX
Lecture 2.3.1 Graph.pptx
PPT
Lecture 5b graphs and hashing
PPTX
PPTX
Graph data structures for ppt for understanding.pptx
PPSX
Unit-6 Graph.ppsx ppt
PPTX
NON-LINEAR DATA STRUCTURE-Graphs.pptx
PPTX
Graph terminology and algorithm and tree.pptx
PDF
unit-3-dsa-graph introduction to grapgh and graph type
PPTX
Graph Theory in Theoretical computer science
PPTX
Data Structure of computer science and technology
PDF
FREQUENT SUBGRAPH MINING ALGORITHMS - A SURVEY AND FRAMEWORK FOR CLASSIFICATION
PDF
graph_theory_1-11.pdf___________________
PPT
Graph theory concepts complex networks presents-rouhollah nabati
PPTX
Graphs aktu notes computer networks.pptx
PDF
The Graph Abstract Data Type-DATA STRUCTURE.pdf
PPTX
VANU no sql ppt.pptx
PPTX
Vanmathy no sql
PPTX
logic.pptx
PPTX
Graphs.pptx
Slides Chapter10.1 10.2
Lecture 2.3.1 Graph.pptx
Lecture 5b graphs and hashing
Graph data structures for ppt for understanding.pptx
Unit-6 Graph.ppsx ppt
NON-LINEAR DATA STRUCTURE-Graphs.pptx
Graph terminology and algorithm and tree.pptx
unit-3-dsa-graph introduction to grapgh and graph type
Graph Theory in Theoretical computer science
Data Structure of computer science and technology
FREQUENT SUBGRAPH MINING ALGORITHMS - A SURVEY AND FRAMEWORK FOR CLASSIFICATION
graph_theory_1-11.pdf___________________
Graph theory concepts complex networks presents-rouhollah nabati
Graphs aktu notes computer networks.pptx
The Graph Abstract Data Type-DATA STRUCTURE.pdf
VANU no sql ppt.pptx
Vanmathy no sql
logic.pptx
Graphs.pptx
Ad

Recently uploaded (20)

PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
UNIT 4 Total Quality Management .pptx
PDF
composite construction of structures.pdf
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPT
Project quality management in manufacturing
PPTX
Geodesy 1.pptx...............................................
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
PPT on Performance Review to get promotions
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Digital Logic Computer Design lecture notes
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
web development for engineering and engineering
CYBER-CRIMES AND SECURITY A guide to understanding
Model Code of Practice - Construction Work - 21102022 .pdf
UNIT 4 Total Quality Management .pptx
composite construction of structures.pdf
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Project quality management in manufacturing
Geodesy 1.pptx...............................................
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Sustainable Sites - Green Building Construction
OOP with Java - Java Introduction (Basics)
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPT on Performance Review to get promotions
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Digital Logic Computer Design lecture notes
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
web development for engineering and engineering

Spanningtreesppt

  • 2. What is a graph? Seattle New York L.A. Tokyo Sydney Seoul 128 140 181 30 16 56
  • 3. Graphs graph: A data structure containing: a set of vertices V, (sometimes called nodes) a set of edges E, where an edge represents a connection between 2 vertices. Graph G = (V, E) an edge is a pair (v, w) where v, w are in V the graph at right: V = {a, b, c, d} E = {(a, c), (b, c), (b, d), (c, d)} degree: number of edges touching a given vertex. at right: a=1, b=2, c=3, d=2 a c b d
  • 4. Graph examples For each, what are the vertices and what are the edges? Web pages with links Methods in a program that call each other Road maps (e.g., Google maps) Airline routes Facebook friends Course pre-requisites Family trees Paths through a maze
  • 5. Paths path: A path from vertex a to b is a sequence of edges that can be followed starting from a to reach b. can be represented as vertices visited, or edges taken example, one path from V to Z: {b, h} or {V, X, Z} What are two paths from U to Y? path length: Number of vertices or edges contained in the path. neighbor or adjacent: Two vertices connected directly by an edge. example: V and X X U V W Z Y a c b e d f g h
  • 6. Weighted graphs weight: Cost associated with a given edge. Some graphs have weighted edges, and some are unweighted. Edges in an unweighted graph can be thought of as having equal weight (e.g. all 0, or all 1, etc.) Most graphs do not allow negative weights. example: graph of airline flights, weighted by miles between cities: ORD PVD MIA DFW SFO LAX LGA HNL
  • 7. Directed graphs directed graph ("digraph"): One where edges are one-way connections between vertices. If graph is directed, a vertex has a separate in/out degree. A digraph can be weighted or unweighted. Is the graph below connected? Why or why not? a d b e g f c
  • 8. Spanning trees  Suppose you have a connected undirected graph   Connected: every node is reachable from every other node. Undirected: edges do not have an associated direction     ...thus in the Mathematical field of graph theory, a spanning tree of the graph is a connected sub-graph in which there are no cycles. A Spanning tree for a graph has no cycles but still connects to every house. If G is a connected graph with n vertices and m edges, spanning tree of G must have n-1 edges, and no. of edges deleted from G to get a spanning tree must be m-(n-1)=m-n+1. A Graph may have many spanning trees; for instance the complete graph on four vertices. A connected, undirected graph Four of the spanning trees of the graph 8
  • 9. Finding Spanning Trees Spanning trees can be found in linear time by simply performing breadth-first search or depth-first search. These graph search algorithms are only dependent on the number of vertices in the graph, so they are quite fast. Breadth-first search will use a queue to hold vertices to explore later. depth-first search will use a stack. In either case, a spanning tree can be constructed by connecting each vertex with the vertex that was used to discover it.
  • 10. Unfortunately, search algorithms are not well suited for parallel or distributed computing, an area in which spanning trees are popular. There are, however, algorithms that are designed to find spanning trees in a parallel setting.
  • 11. 4 Finding a spanning tree  To find a spanning tree of a graph, Pick an initial node and call it part of the spanning tree do a search from the initial node: each time you find a node that is not in the spanning tree, add to the spanning tree both the new node and the edge you followed to get to it. An undirected graph One possible result of a BFS starting from top One possible result of a DFS starting from top
  • 12. Properties of a spanning tree There are a few general properties of spanning trees. A connected graph can have more than one spanning tree. All possible spanning trees for a graph G have the same number of edges and vertices. Spanning trees do not have any cycles. Spanning trees are all minimally connected. That is, if any one edge is removed, the spanning tree will no longer be connected. Adding any edge to the spanning tree will create a cycle. So, a spanning tree is maximally acyclic. Spanning trees have |n|-1 edges, where |n| is the number of vertices
  • 14. BFS