Comp 245 Data Structures Graphs.

Slides:



Advertisements
Similar presentations
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Advertisements

Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 8, Part I Graph Algorithms.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Graphs By JJ Shepherd. Introduction Graphs are simply trees with looser restrictions – You can have cycles Historically hard to deal with in computers.
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
Introduction to Graphs
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Breadth First Search (BFS) Part 2 COMP171. Graph / Slide 2 Shortest Path Recording * BFS we saw only tells us whether a path exists from source s, to.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Computer Science 112 Fundamentals of Programming II Introduction to Graphs.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
Chapter 14 Graphs. © 2004 Pearson Addison-Wesley. All rights reserved Terminology G = {V, E} A graph G consists of two sets –A set V of vertices,
COSC 2007 Data Structures II Chapter 14 Graphs III.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Common final examinations When: Wednesday, 12/11, 3:30-5:30 PM Where: Ritter Hall - Walk Auditorium 131 CIS 1166 final When: Wednesday, 12/11, 5:45-7:45.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
COSC 2007 Data Structures II
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Graphs Upon completion you will be able to:
Source: CSE 214 – Computer Science II Graphs.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
Chapter 05 Introduction to Graph And Search Algorithms.
Backtracking Algorithm Depth-First Search Text Read Weiss, § 9.6 Depth-First Search and § 10.5 Backtracking Algorithms.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Graphs Chapter 20.
Unit 10 Graphs (1) King Fahd University of Petroleum & Minerals
Graphs Representation, BFS, DFS
Introduction to Graphs
Csc 2720 Instructor: Zhuojun Duan
Introduction to Graphs
Ellen Walker CPSC 201 Data Structures Hiram College
Common final examinations
CS120 Graphs.
Graphs Representation, BFS, DFS
Graphs Chapter 13.
Graphs Chapter 15 explain graph-based algorithms Graph definitions
Graphs Chapter 11 Objectives Upon completion you will be able to:
Graphs.
Chapter 11 Graphs.
Yan Shi CS/SE 2630 Lecture Notes
Algorithms and data structures
Chapter 15 Graphs © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Chapter 14 Graphs © 2006 Pearson Addison-Wesley. All rights reserved.
Chapter 16 1 – Graphs Graph Categories Strong Components
Graphs.
Graphs.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Graphs.
Chapter 9 Graph algorithms
GRAPHS.
Introduction to Graphs
Introduction to Graphs
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

Comp 245 Data Structures Graphs

Introduction to the Graph ADT A graph can be defined as a set of points connected by lines. The graph ADT can be defined this way also; the set of points will be called nodes or vertices and the set of lines will be called edges. A tree is a graph but a graph is not necessarily a tree! A tree is a subset of a graph!

An Abstract View of Graphs A tree imposes a hierarchical view of data, a graph does not have to impose any kind of hierarchy.

Graph Terminology Undirected Directed If a graph is undirected an edge essentially goes in both directions, in a directed graph an edge travels in one direction.

Graph Terminology Connected Disconnected A graph is connected if every node can reach every other node!

Graph Terminology Complete A graph is complete if each node can reach every other node directly.

Graph Terminology Other Terms Weighted Path Cycle Adjacent C B A F D 20 10 100 40 25 30 Other Terms Weighted Path Cycle Adjacent

Implementing a Graph Adjacency Matrix B F C E G H Adjacency Matrix 1 2 3 4 5 6  0  1 0  1  1   Map A B C E F G H 1 2 3 4 5 6

Implementing a Graph Adjacency List B F C E G H A B C E F G H

Graph Traversals A graph traversal can start at any node How many nodes can it reach; this is a measure of “connectedness” Utilize the “backtracking” idea to do a traversal

Can We Connect to a Node? (Traverse from a given node) B F C E G H From E can we get to H (E->H)? PUSH all moves from E onto stack ZERO OUT E column (Breadcrumbing) If stack is EMPTY, node is disconnected Otherwise, POP stack to get next move If this is node desired then finished, otherwise repeat process 1 2 3 4 5 6  0  1 0  1  1   A B C E F G H 1 2 3 4 5 6

Dijkstra’s Shortest Path Algorithm Used with a weighted, possibly directed graph. Will calculate the shortest path, least cost, or minimum distance from an “origin” node in a graph to every other node it is “connected” to in the graph.

Dijkstra’s Algorithm A is “origin” node B C D E F G H 3 1 2 4 5

Dijkstra’s Algorithm Shortest Path Table V Known dv Pv A 1 - B 3 C 4 D 2 E F G 5 H 6 A B C D E F G H 3 1 2 4 5 V – visited node Known – indicates we “know” the shortest path dv – distance (weight, cost, etc…) from “origin” node to this node Pv – previous node

Dijkstra’s Algorithm Shortest Path Table - Interpreting V Known dv Pv A 1 - B 3 C 4 D 2 E F G 5 H 6 A B C D E F G H 3 1 2 4 5 Path To: Distance Path B 3 A - B C 4 A - B - C D 2 A - D E A - E F A - D - F G 5 A - D - F - G H 6 A - D - F - H

Practice Create the Shortest Path Table D C F G E 30 50 40 20 5 10 60

Practice Create the Shortest Path Table V Known dv Pv A 1 - B 30 C 50 D 20 E 40 F G A B D C F G E 30 50 40 20 5 10 60 Path To: Distance Path B 30 A - B C 50 A - C D 20 A - D E 40 A - B - E F A - D - F G A - D - G