Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Cpt S 223 – Advanced Data Structures Graph Algorithms: Introduction
Graphs CSCI 2720 Spring 2005.
Review Binary Search Trees Operations on Binary Search Tree
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
CS 206 Introduction to Computer Science II 11 / 11 / Veterans Day Instructor: Michael Eckmann.
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
CS 206 Introduction to Computer Science II 10 / 31 / 2008 Happy Halloween!!! Instructor: Michael Eckmann.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
Introduction to Graphs
Introduction to Graphs What is a Graph? Some Example applications of Graphs. Graph Terminologies. Representation of Graphs. –Adjacency Matrix. –Adjacency.
1 Graph Introduction Definitions. 2 Definitions I zDirected Graph (or Di-Graph) is an ordered pair G=(V,E) such that yV is a finite, non-empty set (of.
CS 206 Introduction to Computer Science II 11 / 03 / 2008 Instructor: Michael Eckmann.
CSE 373: Data Structures and Algorithms Lecture 18: Graphs II 1.
CS/ENGRD 2110 Object-Oriented Programming and Data Structures Fall 2014 Doug James Lecture 17: Graphs.
Topological Sort Introduction. Definition of Topological Sort. Topological Sort is Not Unique. Topological Sort Algorithm. An Example. Implementation.
CS2420: Lecture 36 Vladimir Kulyukin Computer Science Department Utah State University.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Intro to Graphs CSIT 402 Data Structures II. CSIT 402 Graph Introduction2 Graphs Graphs are composed of ›Nodes (vertices) Can be labeled ›Edges (arcs)
Directed graphs Definition. A directed graph (or digraph) is a pair (V, E), where V is a finite non-empty set of vertices, and E is a set of ordered pairs.
1 Graphs Algorithms Sections 9.1, 9.2, and Graphs v1v1 v2v2 v5v5 v7v7 v8v8 v3v3 v6v6 v4v4 A graph G = (V, E) –V: set of vertices (nodes) –E: set.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Chapter 9 Graph Algorithms Real-life graph problems Algorithms for some graph problems Choice of data structures for graph problems.
Lecture 13 Graphs. Introduction to Graphs Examples of Graphs – Airline Route Map What is the fastest way to get from Pittsburgh to St Louis? What is the.
Computer Science 112 Fundamentals of Programming II Introduction to Graphs.
U n i v e r s i t y o f H a i l ICS 202  2011 spring  Data Structures and Algorithms  1.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs. 2 Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
COSC 2007 Data Structures II Chapter 14 Graphs I.
CS 146: Data Structures and Algorithms July 16 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects two different vertices. Edges are.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
CSC2100B Tutorial 10 Graph Jianye Hao.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 10 Prepared by İnanç TAHRALI.
Graphs Upon completion you will be able to:
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
Copyright © Curt Hill Graphs Definitions and Implementations.
Chapter 9: Graphs.
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.
Graphs and Shortest Paths Using ADTs and generic programming.
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
1 CSE 332: Graphs Richard Anderson Spring Announcements This week and next week – Graph Algorithms Reading, Monday and Wednesday, Weiss
رياضيات متقطعة لعلوم الحاسب MATH 226. Chapter 10.
Subject Four Graphs Data Structures. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes.
Topological Sorting.
Graphs Lecture 19 CS2110 – Spring 2013.
Introduction to Graphs
Basic Concepts Graphs For more notes and topics visit:
GRAPHS Lecture 16 CS2110 Fall 2017.
Introduction to Graphs
More Graph Algorithms.
Refresh and Get Ready for More
Graph Algorithm.
"Learning how to learn is life's most important skill. " - Tony Buzan
Graphs Chapter 11 Objectives Upon completion you will be able to:
Topological Sort CSE 373 Data Structures Lecture 19.
Graphs.
Richard Anderson Autumn 2016 Lecture 5
Graphs G = (V, E) V are the vertices; E are the edges.
GRAPHS Lecture 17 CS2110 Spring 2018.
Richard Anderson Winter 2019 Lecture 6
Richard Anderson Lecture 5 Graph Theory
GRAPHS.
Introduction to Graphs
Presentation transcript:

Introduction to Graphs

Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected

Introduction: Formal Definition A graph G = (V,E) consists of a finite set of vertices, V, and a finite set of edges E. Each edge is a pair (v,w) where v, w  V

Introduction: Formal Definition A directed graph, or digraph, is a graph in which the edges are ordered pairs –(v, w) ≠ (w, v) An undirected graph is a graph in which the edges are unordered pairs –(v, w) == (w, v)

Introduction: Directed Graphs In a directed graph, the edges are arrows. Directed graphs show the flow from one node to another and not vise versa.

Introduction: Undirected Graphs In a directed graph, the edges are lines. Directed graphs show a relationship between two nodes.

Terminology In the directed graph above, b is adjacent to a because (a, b)  E. Note that a is not adjacent to b. A is a predecessor of node B B is a successor of node A The source of the edge is node A, the target is node B

Terminology In the undirected graph above, a and b are adjacent because (a,b)  E. a and b are called neighbors.

Terminology A path is a sequence of vertices w 1, w 2,…w n such that (w i, w i+1 )  E, 1 <= i < n, and each vertex is unique except that the path may start and end on the same vertex The length of the path is the number of edges along the path

Terminology An acyclic path is a path where each vertex is unique A cyclic path is a path such that –There are at least two vertices on the path –w 1 = w n (path starts and ends at same vertex)

Test Your Knowledge Cyclic or Acyclic?

Terminology A directed graph that has no cyclic paths is called a DAG (a Directed Acyclic Graph). An undirected graph that has an edge between every pair of vertices is called a complete graph. Note: A directed graph can also be a complete graph; in that case, there must be an edge from every vertex to every other vertex.

Test Your Knowledge Complete, or “Acomplete” (Not Complete)

Terminology An undirected graph is connected if a path exists from every vertex to every other vertex A directed graph is strongly connected if a path exists from every vertex to every other vertex A directed graph is weakly connected if a path exists from every vertex to every other vertex, disregarding the direction of the edge

Test Your Knowledge Connected, Strongly connected, or Weakly connected

Terminology A graph is known as a weighted graph if a weight or metric is associated with each edge.

Uses for Graphs Computer network: The set of vertices V represents the set of computers in the network. There is an edge (u, v) if and only if there is a direct communication link between the computers corresponding to u and v.

Uses for Graphs Precedence Constraints: Suppose you have a set of jobs to complete, but some must be completed before others are begun. (For example, Atilla advises you always pillage before you burn.) Here the vertices are jobs to be done. Directed edges indicate constraints; there is a directed edge from job u to job v if job u must be done before job v is begun.

Uses for Graphs Two-Player Game Tree: All of the possibilities in a board game like chess can be represented in a graph. Each vertex stands for one possible board position. (For chess, this is a very big graph!)

Topological Sort Don’t burn before you pillage!

Topological Sort Informally, a topological sort is a linear ordering of the vertices of a DAG in which all successors of any given vertex appear in the sequence after that vertex.

Method to the Madness One way to find a topological sort is to consider the in-degrees of the vertices. (The number of incoming edges is the in- degree). Clearly the first vertex in a topological sort must have in-degree zero and every DAG must contain at least one vertex with in-degree zero.

Simple Topological Sort Algorithm Repeat the following steps until the graph is empty: –Select a vertex that has in-degree zero. –Add the vertex to the sort. –Delete the vertex and all the edges emanating from it from the graph.

Test Your Knowledge Give a topological sort for this graph, it should be evident that more than one solution exists for this problem.