Computer Science 112 Fundamentals of Programming II Introduction to Graphs.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Analysis of Algorithms CS 477/677
Cpt S 223 – Advanced Data Structures Graph Algorithms: Introduction
Computer Science 112 Fundamentals of Programming II Overview of Collections.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
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.
Fundamentals of Python: From First Programs Through Data Structures
Chapter 8, Part I Graph Algorithms.
Data Structure and Algorithms (BCS 1223) GRAPH. Introduction of Graph A graph G consists of two things: 1.A set V of elements called nodes(or points or.
 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.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Graph & BFS.
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
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.
1 Data Structures and Algorithms Graphs I: Representation and Search Gal A. Kaminka Computer Science Department.
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 11 / 05 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 09 / 2009 Instructor: Michael Eckmann.
Important Problem Types and Fundamental Data Structures
Computer Science 112 Fundamentals of Programming II Graph Algorithms.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Chapter 2 Graph Algorithms.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
1 abstract containers hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1) set.
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
 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.
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 CSE 2011 Winter June Graphs A graph is a pair (V, E), where  V is a set of nodes, called vertices  E is a collection of pairs.
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.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
COSC 2007 Data Structures II Chapter 14 Graphs I.
Data Structures CSCI 132, Spring 2014 Lecture 38 Graphs
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.
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
DATA STRUCTURES AND ALGORITHMS Lecture Notes 10 Prepared by İnanç TAHRALI.
Graph. Graph Usage I want to visit all the known famous places starting from Seoul ending in Seoul Knowledge: distances, costs Find the optimal(distance.
Graphs and Paths : Chapter 15 Saurav Karmakar
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Graph Representations And Traversals. Graphs Graph : – Set of Vertices (Nodes) – Set of Edges connecting vertices (u, v) : edge connecting Origin: u Destination:
Fundamentals of Programming II Introduction to Trees
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
CS202 - Fundamental Structures of Computer Science II
CMSC 341 Lecture 21 Graphs (Introduction)
Comp 245 Data Structures Graphs.
Graph.
Refresh and Get Ready for More
Graphs Chapter 13.
Graphs CSE 2011 Winter November 2018.
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.
Graphs Chapter 11 Objectives Upon completion you will be able to:
CS223 Advanced Data Structures and Algorithms
Chapter 9: Graphs Basic Concepts
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
Graph Theory By Amy C. and John M..
Graphs.
ITEC 2620M Introduction to Data Structures
Graphs G = (V, E) V are the vertices; E are the edges.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Important Problem Types and Fundamental Data Structures
Chapter 9: Graphs Basic Concepts
For Friday Read chapter 9, sections 2-3 No homework
Presentation transcript:

Computer Science 112 Fundamentals of Programming II Introduction to Graphs

Categories of Collections Unordered – bag, set, dictionary Linear – list, stack, queue Hierarchical – tree, heap Graph

What Is A Graph? A collection of items, each of which can have zero or more successors and zero or more predecessors Trees and lists are just special cases of graphs

Graphs in Everyday Life A road map A map of airline routes Links between Web pages Relationships in a social network Diagram of flow capacities in a communication or transportation network

Examples FDCABEGABCDEFGFDCABEG

Vertex, Edge, Label, and Weight The nodes in a graph are also called vertices The connections between vertices are called edges Vertices and edges can be labeled or unlabeled A numeric edge label is also called a weight

Examples

Connections A graph is connected if there is at least one edge from each vertex to some other vertex A graph is complete if there is an edge from each vertex to every other vertex

Examples

Paths and Cycles A path is a sequence of edges that allows one vertex to be reached from another vertex A simple path is a path in which a vertex is not visited more than once A cycle is a path in which a vertex is visited more than one

Examples A A B B D D C C A A B B C C Simple path: ABC Cycle: BCD

Directed Graphs (Digraphs) Each edge in a directed graph points in one direction, allowing movement from a source vertex to a destination vertex These edges are called directed edges

Directed Acyclic Graphs (DAGs) A directed acyclic graph is a directed graph with no cycles

Directed and Undirected Graphs The edges in an undirected graph support movement in both directions

Sparse and Unsparse Graphs Sparse graphs are connected graphs with a minimal number of edges (roughly N edges) Unsparse graphs have close to the maximum number of edges (roughly N 2 edges)

Adjacent Vertices Vertex A is adjacent to vertex B if there is a directed edge from B to A

Incident Edges Edge BA is incident to vertex B if it is a directed edge from B to A

Adjacency Matrix Representation A two-dimensional array A with N rows and N columns Each cell A[i][j] contains 1 if there is an edge from vertex i to vertex j, or contains 0 otherwise

Adjacency Matrix (Directed Graph) When an edge has a weight, the weight can go in the matrix, with a non-weight value indicating the absence of an edge Non-numeric labels can be kept in a separate array A A B B D D C C A0A 1B1B 2C2C 3D3D 0 A 1 B 2 C 3 D

Adjacency Matrix (Undirected Graph) A A B B D D C C A0A 1B1B 2C2C 3D3D 0 A 1 B 2 C 3 D

Adjacency List Representation An array A of N linked lists The ith linked list contains a node for vertex j if and only if there is an edge from vertex i to vertex j

Adjacency List (Undirected Graph) When an edge has a weight, the weight can also go in the corresponding node, and the nodes can be ordered from least cost to greatest cost Undirected graphs have two nodes for each edge 0 A 1 B 2 C A A B B D D C C D

Analysis: Detect an Edge Constant time for adjacency matrix, which uses the vertex numbers as indexes into the array Linear with length of adjacency list, because we index into the array and then search a linked list

Analysis: Return the Adjacent Vertices Constant time for the adjacency list, because we index into the array and then return a copy of its linked list Linear with the total number of vertices for the adjacency matrix, because we must traverse the row indexed by the vertex

Analysis: Memory Usage Adjacency matrix always has N 2 array cells, so some may go to waste, especially with sparse graphs The number of nodes equals the number of edges in adjacency list, so memory becomes an issue only when graphs are really dense

For Monday Graph Algorithms