introduction to graphs n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Introduction to Graphs PowerPoint Presentation
Download Presentation
Introduction to Graphs

Loading in 2 Seconds...

play fullscreen
1 / 38

Introduction to Graphs - PowerPoint PPT Presentation


  • 134 Views
  • Uploaded on

Introduction to Graphs. Graphs: what are they?. Representations of pairwise relationships Collections of objects under some specified relationship. Graphs: what are they mathematically?. A graph G is a pair (V,E) V is a set of vertices (nodes) E is a set of pairs ( a,b ), a,b  V

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Introduction to Graphs' - espen


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
graphs what are they
Graphs: what are they?
  • Representations of pairwise relationships
  • Collections of objects under some specified relationship
graphs what are they mathematically
Graphs: what are they mathematically?
  • A graph G is a pair (V,E)
    • V is a set of vertices (nodes)
    • E is a set of pairs (a,b), a,b V
  • V is the set of relatable objects
  • E is the set of relationships
a visual example
A Visual Example

1

3

2

4

5

G = ( {1,2,3,4,5}, {(1,2), (1,4), (2,3), (2,4), (1,5)} )

directed graphs
Directed Graphs
  • In a directed graph
    • (a,b)  E does not imply (b,a)  E
  • Undirected graphs are a subset
    • (a,b)  E if and only if (b,a)  E
  • Visually, directed graphs are drawn with arrows
directed graph example
Directed Graph Example

1

3

2

4

5

G = ( {1,2,3,4,5},

{ (1,5), (2,1), (2,3), (2,4), (3,2), (4,1) } )

weighted graphs
Weighted Graphs
  • Have weights associated with edges
  • Can be directed or undirected
  • Can have pairs, in a directed graph, where the weights from (a,b) have no relationship on the weights from (b,a)
weighted graph example
Weighted Graph Example

1

3.2

3

2

π

42

666

-5

777

4

5

G = ( {1,2,3,4,5},

{ (1,5,-5), (2,1,3.2),

(2,3,42), (3,2, π),

(2,4,777), (4,1,666) } )

graph representation
Graph Representation
  • How to represent in memory?
  • Two common ways:
    • Adjacency Lists
    • Adjacency Matrix
undirected graph example
Undirected Graph Example

G = ( {1,2,3,4,5}, {(1,2), (1,4), (2,3), (2,4), (1,5)} )

1

2

3

4

5

2

4

5

1

3

4

2

1

2

1

directed graph example1
Directed Graph Example

G = ( {1,2,3,4,5},

{ (1,5), (2,1), (2,3), (2,4), (3,2), (4,1) } )

1

2

3

4

5

5

1

3

4

2

1

undirected graph example1
Undirected Graph Example

G = ( {1,2,3,4,5}, {(1,2), (1,4), (2,3), (2,4), (1,5)} )

directed graph example2
Directed Graph Example

G = ( {1,2,3,4,5},

{ (1,5), (2,1), (2,3), (2,4), (3,2), (4,1) } )

dfs algorithm
DFS Algorithm
  • Algorithm DFS ( G )

for i = 1 to n do // Initialize all vertices are unvisited

status[i] = unvisited

parent[i] = NULL

for i = 1 to n do

if (status[i] == unvisited) // If there exits an invisited vertex, start traversal

DF-Travel(i)

Algorithm DF-Travel ( v )

status[v] = visited

for each vertex u adjacent to v do

if status[u] == unvisited then

parent[u] = v

DF-Travel ( u )

breadth first search algorithm
Breadth First Search Algorithm
  • Breadth First Search (BSF):
    • Initially all vertices of the graph are unvisited.
    • Start visiting the graph from any vertex, say v .
      • Visit each unvisited adjacent vertex of v.
      • Repeat the process for each vertex visited.
    • This process stops when all vertices reachable from v are visited.
  • This method is called breadth first search, since it works outward from a center point, much like the ripples created when throwing a stone into a pond. It moves outward in all directions, one level at a time.
what is the minimum spanning tree mst
What is the Minimum Spanning tree (MST)?
  • Consider Oil Well example.=>
  • Resultant graph is a tree which spannes all vertices of the graph. Hence called spanning tree.   
  •  The spanning tree with minimum cost is called Minimum Spanning tree (MST).
minimum spanning tree1
Minimum Spanning Tree
  • Required: Connect all nodes at minimum cost.
  • Cost is sum of edge weights
  • Can start at any node
  • Unique solution.
    • Can come from different sets of edges
  • Two algorithms
    • Prim’s
    • Kruskal’s
finding a mst
Finding a MST
  • Principal greedy methods: algorithms by Prim and Kruskal
  • Prim
    • Grow a single tree by repeatedly adding the least cost edge that connects a vertex in the existing tree to a vertex not in the existing tree
  • Kruskal
    • Grow a tree by repeatedly adding the least cost edge that does not introduce a cycle among the edges included so far
prim salgorithm
Prim’sAlgorithm

Start with any vertex.

All its edges are candidates.

Stop looking when all vertices are picked

Otherwise repeat…

Pick minimum edge (no cycles) and connect the adjacent vertex

Add all edges from that new vertex to our “candidates”

the shortest path problem
The Shortest Path Problem
  • Given a directed, weighted graphG = ( V, E )
  • What is the shortest path from the start vertex to some end vertex?
  • Minimize the sum of the edge weights
dijkstra s shortest path algorithm
Dijkstra's Shortest Path Algorithm
  • In a graph in which edges have costs ..
  • Find the shortest path from a source to a destination

Surprisingly ..

  • While finding the shortest path from a source to one destination, we can find the shortest paths to all over destinations as well !
dijkstra algorithm
Dijkstra Algorithm
  • Problem:
    • From a given source vertex s ∈ V, find the shortest-path weights d(s, v)for all v∈V.
  • IDEA: Greedy.
    • Maintain a set S of vertices whose shortest-path distances from s are known.
    • At each step add to S the vertex v ∈ V –S whose distance estimate from s is minimal.
    • Update the distance estimates of vertices adjacent to v.
dijkstra s shortest path algorithm1
Dijkstra's Shortest Path Algorithm
    • For a graph G = ( V, E )
  • Dijkstra’s algorithm keeps two sets of vertices:
    • S Vertices whose shortest paths have already been determined
    • V-S Remainder
  • Also
    • d Best estimates of shortest path to each vertex
    • Π Predecessors for each vertex
dijkstra s shortest path algorithm2
Dijkstra's Shortest Path Algorithm
  • Find shortest path from s to t.