We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Published byJaylan Newingham
Modified over 2 years ago
AQA Computing A2 © Nelson Thornes 2009 Section Section 2.5: Graphs and Trees Adjacency Matrix and Adjacency List
AQA Computing A2 © Nelson Thornes 2009 Section Learning Objectives In this presentation you will learn how a graph (directed or undirected) can be represented as an adjacency matrix or as an adjacency list. You will be able to explain the difference between these two methods, including the advantages of each.
AQA Computing A2 © Nelson Thornes 2009 Section Representing a graph There are two ways of representing a graph so that it can be processed by a computer program: Adjacency Matrix Adjacency List To look at how these work we will use the following undirected graph:
AQA Computing A2 © Nelson Thornes 2009 Section 2.5 Adjacency Matrix A graph can be represented using a two-dimensional matrix; this is called an adjacency matrix. Visually, this is like a table which records information about which vertices have an edge connecting them i.e. which vertices are adjacent. Each vertex has a row in the table. Each vertex has a column in the table. A 1 is placed in the intersection of a vertexs row with another vertexs column if there is an edge between them. A 0 is placed in all of the other cells to denote that there is no edge connecting the two vertices. 4
AQA Computing A2 © Nelson Thornes 2009 Section 2.5 Adjacency Matrix We will now construct an adjacency matrix for our example graph VERTEX Start with vertex 1; there is an edge connecting it to vertex 2 so we place a 1 in row 1, column 2. As there is an edge connecting vertex 1 to vertex 2 there is also one from vertex 2 to vertex 1 so place a 1 in row 2, column 1. There is an edge connecting vertex 1 to vertex 3 so place a 1 in row 1, column 3 and also in row 3, column 1. There is an edge connecting vertex 1 to vertex 4 so place a 1 in row 1, column 4 and also in row 4, column 1. Then look at vertex 2. There is an edge between vertices 2 & 3 so put a 1 in row 2, column 3 and in row 3, column 2. Then look at the remaining vertices, placing a 1 in the cells which represent vertices that are connected in the graph. Then place a 0 in all the other cells, as there are no edges connecting the corresponding vertices in the graph. Our example undirected graph has now been represented as an adjacency matrix. Notice that the adjacency matrix is symmetric about the top-left to bottom-right diagonal
AQA Computing A2 © Nelson Thornes 2009 Section 2.5 Adjacency List An alternative to an adjacency matrix is an adjacency list, which can be used to indicate which vertices are next to each other. For each vertex, a list of the vertices connected to is maintained. 6
AQA Computing A2 © Nelson Thornes 2009 Section 2.5 Adjacency List We will now construct an adjacency list for our example graph VertexAdjacent Vertices , 4 1, 3, 5 1, 2, 4, 5 1, 3 2, 3, 4 Start with vertex 1. It is connected to vertices 2, 3 and 4. So this is recorded in the adjacency list. Then look at vertex 2. It is connected to vertices 1 and 3. This is recorded in the adjacency list. Then do the same for the other vertices in the graph. The graph has now been represented as an adjacency list.
AQA Computing A2 © Nelson Thornes 2009 Section 2.5 Directed graphs Directed graphs can also be represented as an adjacency matrix or adjacency list. The method is very similar to that for undirected graphs, there are slight differences so that the matrix / list reflect the direction of each edge. In the examples that follow we will use this directed graph:
AQA Computing A2 © Nelson Thornes 2009 Section 2.5 Adjacency Matrix for a Directed Graph We will now construct an adjacency matrix for our example graph. 9 VERTEX Start with vertex 1; there is an edge from it to vertex 2 so we place a 1 in row 1, column We do not put a 1 in row 2, column 1 though as there is not an edge from vertex 2 to vertex 1. There is also an edge from vertex 1 to vertex 3 so we put a 1 in row 1, column 3. Then do the same for the other vertices. There is an edge from vertex 3 to 4 and from vertex 4 to 3 so both these cells have a 1 in the table. Place 0s in the other cells. The adjacency matrix is now complete. Note it is not symmetric.
AQA Computing A2 © Nelson Thornes 2009 Section 2.5 Adjacency List for a Directed Graph We will now construct an adjacency list for our example graph. 10 VertexAdjacent Vertices , 3, 5 4, 5 3 2, 3 Start with vertex 1. There is an edge from it to vertices 2 and 3. So this is recorded in the adjacency list. We do not add 4 to the list as there is no edge from vertex 1 to vertex 4. Then look at vertex 2. There is an edge from vertex 2 to vertex 3. This is recorded in the adjacency list. Then do the same for the other vertices in the graph. The graph has now been represented as an adjacency list
AQA Computing A2 © Nelson Thornes 2009 Section 2.5 Adjacency Matrix vs Adjacency List It is quicker to find out if there is an edge between 2 vertices using an adjacency matrix (you only have to look at one item; in an adjacency list you may have to look at all items in a vertexs list to see if there is an edge to another vertex). However, an adjacency list can require significantly less space as there is no wastage – it only stores information about which edges do exist in the graph; an adjacency matrix stores information about each possible edge (whether it exists or not). For large graphs which have many vertices but few edges an adjacency list is normally preferable. If a graph has many edges an adjacency matrix is normally the best way of representing the graph. 11
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.
Design and Analysis of Algorithms Introduction to graphs, representations of a graph Haidong Xue Summer 2012, at GSU.
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.
Introduction to Graphs What is a Graph? Some Example applications of Graphs. Graph Terminologies. Representation of Graphs. –Adjacency Matrix. –Adjacency.
Source: CSE 214 – Computer Science II Graphs.
Copyright ©2015 Pearson Education, Inc. All rights reserved.
1 After completing this lesson, you will be able to: Insert a table. Navigate and select cells within a table. Merge table cells. Insert and delete columns.
1 Algorithms CSCI 235, Fall 2015 Lecture 32 Graphs I.
Vocabulary and Representations of Graphs. NC Standard Course of Study Competency Goal 1: The learner will use matrices and graphs to model relationships.
1 Data Structures CSCI 132, Spring 2014 Lecture 38 Graphs.
Graph Graph Types of Graphs Types of Graphs Data Structures to Store Graphs Data Structures to Store Graphs Graph Definitions Graph Definitions.
Chapter 3. Relations Definitions Relations Binary relations Domain Range Vertex Direct edge Loops Reflective Relations Sympatric Relations Anti Symmetric.
1 Introduction to Graphs What is a Graph? Some Example applications of Graphs. Graph Terminologies. Representation of Graphs. –Adjacency Matrix. –Adjacency.
Graphs, relations and matrices Section 7.4. Overview Graph structures are valuable because they can represent relationships among pairs of objects, and.
Chapter 1 Section 1.6 Algebraic Properties of Matrix Operations.
Function Of Microsoft Words Tables. Where Table section is located Table section is located on top row with File, Edit, View, Insert, Format, Tools, Window.
Review Binary Search Trees Operations on Binary Search Tree Inserting a Node Searching a Node Deleting a Node Expression Tree Decision Tree.
Sections What is a “quadratic” function?
TABLES Why Make a Table Steps to Making a Table Rows Vs. Colums Resources By: Morgan Jahnke 2 nd Grade Math.
Depth-First Search COMP171. Graph / Slide 2 Summary of BFS * Graph and representations * BFS, and BFS tree * Complexity of BFS.
Space Figures & Cross- Sections Section Vocab Polyhedron - 3-dimensional figure whose surfaces are polygons Face of polyhedron - each polygon that.
Author: Jie chen and Yousef Saad IEEE transactions of knowledge and data engineering.
Periodic Table - Start a New Page - Add it to your TOC.
Graph Implementations Chapter 29 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Honors Geometry. We learned how to set up a polygon / vertex matrix We learned how to add matrices We learned how to multiply matrices.
What is a graph? What is a graph? Directed vs. undirected graphs Directed vs. undirected graphs Trees vs graphs Trees vs graphs Terminology: Degree.
1 Discrete Math Graphs, representation, isomorphism, connectivity.
Computer Science: A Structured Programming Approach Using C Graphs A graph is a collection of nodes, called vertices, and a collection of segments,
Algorithms (and Datastructures) Lecture 3 MAS 714 part 2 Hartmut Klauck.
Graph Coloring Solution in a Deterministic Machine The deterministic solution to coloring problem uses these steps to assign colors to vertices: 1- Given.
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.
Graph Representations And Traversals. Graphs Graph : – Set of Vertices (Nodes) – Set of Edges connecting vertices (u, v) : edge connecting Origin: u Destination:
MATRIX A set of numbers arranged in rows and columns enclosed in round or square brackets is called a matrix. The order of a matrix gives the number of.
Tables are commonly used to display all manner of data, such as timetables, financial reports, and sports results etc. Tables, just like spreadsheets,
Objective: To us the vertex form of a quadratic equation 5-3 TRANSFORMING PARABOLAS.
CS203 Lecture 15. Modeling Using Graphs 2 For purposes of graph theory, a graph is a mathematical structure used to model pairwise relations between objects.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Fundamental Data Structures and Algorithms (Spring ’05) Recitation Notes: Graphs Slides prepared by Uri Dekel, Based on recitation.
& Problem Solving. You will be able to use the converse of a theorem to construct parallel lines. You will be able to use theorems to find the measures.
Solving Systems of Equations and Inequalities Section 2.1 Two variable linear equations Section 2.2 Three variable linear equations Section 2.3 Matrices.
Graphs – Part III CS 367 – Introduction to Data Structures.
CSE 373 Data Structures and Algorithms Lecture 20: Graphs II.
Solving Systems of Equations and Inequalities Section 3.1A-B Two variable linear equations Section 3.1C Matrices Resolution of linear systems Section 3.1D.
Module 5 – Networks and Decision Mathematics Chapter 24 – Directed Graphs.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
GRAPH THEORY. A graph is a collection of vertices and edges. An edge is a connection between two vertices (or nodes). One can draw a graph by marking.
1 Applications of BFS and DFS CSE 2011 Winter May 2016.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
PSU CS 311 – Design and Algorithms Analysis Dr. Mohamed Tounsi Backtracking.
© 2017 SlidePlayer.com Inc. All rights reserved.