Graphs: Definitions How would you represent the following?

Slides:



Advertisements
Similar presentations
CS 253: Algorithms Chapter 22 Graphs Credit: Dr. George Bebis.
Advertisements

Analysis of Algorithms CS 477/677
Review Binary Search Trees Operations on Binary Search Tree
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graph A graph, G = (V, E), is a data structure where: V is a set of vertices (aka nodes) E is a set of edges We use graphs to represent relationships among.
CS 206 Introduction to Computer Science II 11 / 11 / Veterans Day Instructor: Michael Eckmann.
1 Representing Graphs. 2 Adjacency Matrix Suppose we have a graph G with n nodes. The adjacency matrix is the n x n matrix A=[a ij ] with: a ij = 1 if.
Graph & BFS.
Introduction to Graphs
Graph & BFS Lecture 22 COMP171 Fall Graph & BFS / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D.
Introduction to Graphs What is a Graph? Some Example applications of Graphs. Graph Terminologies. Representation of Graphs. –Adjacency Matrix. –Adjacency.
CS 206 Introduction to Computer Science II 11 / 03 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.
CSE 321 Discrete Structures Winter 2008 Lecture 25 Graph Theory.
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.
CISC220 Fall 2009 James Atlas Nov 13: Graphs, Line Intersections.
Chapter 9: Graphs Basic Concepts
Graphs CS /02/05 Graphs Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Definition.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Computer Science 112 Fundamentals of Programming II Introduction to Graphs.
Graph Theoretic Concepts. What is a graph? A set of vertices (or nodes) linked by edges Mathematically, we often write G = (V,E)  V: set of vertices,
Representing and Using Graphs
Graphs. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes to each other The set of.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 20.
1 CS104 : Discrete Structures Chapter V Graph Theory.
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.
Graph Introduction, Searching Graph Theory Basics - Anil Kishore.
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.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Graphs Chapter 28 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)
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. Graph Definitions A graph G is denoted by G = (V, E) where  V is the set of vertices or nodes of the graph  E is the set of edges or arcs connecting.
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.
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.
Data Structures & Algorithm Analysis lec(8):Graph T. Souad alonazi
Graphs.
CS 201: Design and Analysis of Algorithms
Introduction to Graphs
Basic Concepts Graphs For more notes and topics visit:
CSE 2331/5331 Topic 9: Basic Graph Alg.
Introduction to Graphs
CS120 Graphs.
CMSC 341 Lecture 21 Graphs (Introduction)
Graph.
Graph & BFS.
Graphs All tree structures are hierarchical. This means that each node can only have one parent node. Trees can be used to store data which has a definite.
Chapter 9: Graphs Basic Concepts
Graph Operations And Representation
Walks, Paths, and Circuits
Chapter 11 Graphs.
Graph Theory By Amy C. and John M..
CSE 373 Data Structures Lecture 17
ITEC 2620M Introduction to Data Structures
Representing Graphs Wade Trappe.
Chapter 14 Graphs © 2006 Pearson Addison-Wesley. All rights reserved.
Graphs Chapter 7 Visit for more Learning Resources.
Graphs G = (V, E) V are the vertices; E are the edges.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
GRAPHS Lecture 17 CS 2110 — Spring 2019.
Chapter 9: Graphs Basic Concepts
CSE 373 Data Structures Lecture 13
Graphs G = (V,E) V is the vertex set.
GRAPHS.
Introduction to Graphs
For Friday Read chapter 9, sections 2-3 No homework
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:

Graphs: Definitions How would you represent the following? A chart of driving distances between cities of the US A network The prerequisite relationship between CS classes A map for the game “Hunt the Wumpus” These problems have similar structure: A collection of objects (cities, computers, classes, caves) connected in some way (roads, cables, precedence relationship, doorways)

Graphs: Definitions Draw a picture where these objects are nodes (vertices) and the connections are links (edges) between vertices. This picture is called a graph. Formally: A graph G=(V,E) consists of a set V whose members are called vertices and a set E whose members are called edges and are pairs of distinct vertices from V.

Graphs: Definitions Adjacent vertices = connected by an edge An edge (u,v) is incident to vertices u and v Degree of a vertex = number of edges incident to it (or, number of adjacent vertices) Path of length k = a sequence (v0, v1, ...vk) such that (vi-1, vi)E A vertex is reachable from another if there is a path between them Weighted graph : each edge has an associated weight

Graphs: Examples w complete graph of 5 vertices, aka K5 u v vertices u and v are adjacent (u,v,w,u) is a cycle v a graph with two connected components u in this graph, u is not reachable from v

Graphs: Representation Adjacency matrix : a |V||V| table A, such that A[vi,vj]= 1, if (vi,vj)E 0, otherwise v1 v2 v3 v4 v5 v1 0 1 1 1 1 v2 1 0 1 0 0 v3 1 1 0 1 0 v4 1 0 1 0 1 v5 1 0 0 1 0 v1 v2 v3 v5 v4

Graphs: Representation Adjacency list : an array A of |V| lists, one for each vertex. For each vV, A[v] contains all the vertices adjacent to v. v1 v2 v1 v2 v3 v4 v5 v2 v3 v4 v5 v1 v3 v2 v1 v4 v3 v5 v4 v1 v3 v5 v1 v4

Graphs: Representation What representation would you use for a sparse graph? (i.e. one that has very few edges) How about a dense graph? How would you modify the adjacency list/matrix definitions for weighted graphs? How long does it take to perform the following operations in each representation? compute the degree of a vertex insert/delete a vertex insert/delete an edge areAdjacent(u,v) How much space does each representation require?

Graphs: Traversal Searching/Traversing a graph = visiting the vertices of a graph by following the edges in a systematic way Example: Given a highway map, find a path from one city to another. What if the graph has cycles? To avoid getting “trapped” in a cycle, mark the vertices that have already been visited.