chapter 15 graphs n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Chapter 15 Graphs PowerPoint Presentation
Download Presentation
Chapter 15 Graphs

Loading in 2 Seconds...

play fullscreen
1 / 11

Chapter 15 Graphs - PowerPoint PPT Presentation


  • 75 Views
  • Uploaded on

Modified. Chapter 15 Graphs. Part C – Graph Algorithms 1. Basic Graph Algorithms. Un-weighted graphs/digraphs Connectivity Cycle detection Shortest path Spanning tree Topological sort. Basic Graph Algorithms. Weighted graphs/digraphs Minimum spanning tree Cheapest path

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 'Chapter 15 Graphs' - suzy


Download Now 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
chapter 15 graphs

Modified

Chapter 15

Graphs

Part C – Graph Algorithms 1

basic graph algorithms
Basic Graph Algorithms
  • Un-weighted graphs/digraphs
    • Connectivity
    • Cycle detection
    • Shortest path
    • Spanning tree
    • Topological sort

Java Software Structures, 4th Edition, Lewis/Chase

basic graph algorithms1
Basic Graph Algorithms
  • Weighted graphs/digraphs
    • Minimum spanning tree
    • Cheapest path
    • Traveling salesman problem

Java Software Structures, 4th Edition, Lewis/Chase

dynamic graphs
Dynamic graphs
  • Adding and removing vertices
  • Adding and removing edges

Java Software Structures, 4th Edition, Lewis/Chase

connectivity
Connectivity
  • For a graph (undirected) how can we determine if it is connected?
  • Answer: Do a depth first traversal and see if all of the vertices are reached.
  • For a digraph, how do can we determine if it is connected?
  • Answer: Do a depth first traversal from every vertex and see if all other vertices are reached.

Java Software Structures, 4th Edition, Lewis/Chase

cycle detection
Cycle detection
  • For a graph, how can we detect if it contains any cycles?
  • Do a depth first traversal and look for “back edges”, edges from current node to a node already visited.
  • For a digraph –
  • Do the same, for every vertex as starting vertex.

Java Software Structures, 4th Edition, Lewis/Chase

finding shortest path un weighted
Finding shortest path (un-weighted)
  • For a graph, how do we find the shortest path (fewest edges) from vertex A to vertex B?
  • Do a breadth first traversal starting at A and going until B is reached, recording the path length and predecessor at each node visited.
  • Need more info stored at each node visited.
  • For a digraph –
  • Same

Java Software Structures, 4th Edition, Lewis/Chase

shortest path form a to b
Shortest path form A to B

create a queue Q

visit A, mark Aas visited, set path length=0, set pred=null,and put A into Q

repeat until B is visited

remove the head element u of Q

for each w: (unvisited) neighbors of u

visit w, mark w, set path length of w, set pred of w=u, and enqueue w

Follow the preds backwards from B to A

Java Software Structures, 4th Edition, Lewis/Chase