Graphs: basic definitions and notation Definition A (undirected, unweighted) graph is a pair G = (V, E), where V = {v 1, v 2,..., v n } is a set of vertices,

Slides:



Advertisements
Similar presentations
Introduction to Functions
Advertisements

One-to-One Functions Recall the definition of a function: A function is a relation (set of ordered pairs) such that for each x-value, there is _________________.
Functions with Inverses Functions with Inverses
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
Section 1.2 Basics of Functions
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
9/8/ Relations and Functions Unit 3-3 Sec. 3.1.
Chapter 4.8: Determine if the Relation is a Function.
What is the domain of the following relation? (use correct notation) { (1, 3), (4, 5.5), (6, 9), (10, 0) }
Section 2.2 Functions  Functions & Graphs  Function Notation & Equations  Applications: Interpolation & Extrapolation 12.2.
Pre-AP Pre-Calculus Chapter 1, Section 5 Parametric Relations and Inverses
Chapter 2 Section 3. Introduction to Functions Goal:Find domain and range, determine if it’s a function, use function notation and evaluate. Definition.
Functions Domain & Range Evaluate with Function Notation.
2.1 “Relations & Functions” Relation: a set of ordered pairs. Function: a relation where the domain (“x” value) does NOT repeat. Domain: “x” values Range:
Bell Ringer 10/30/ Objectives The student will be able to: 1. identify the domain and range of a relation. 2. show relations as sets and mappings.
Math – Graphs of Functions 1. Graph of a function: the graph of all the function’s ordered pairs 2.
Review Functions. Function A function is a special type of relation in which each element of the domain is paired with exactly one element of the range.
Functions Section 5.1.
Relations and Functions
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
8-1: Relations and Functions
Lesson 1 -Introduction to Functions
Find the Inverse and Graph the Functions
College Algebra Chapter 2 Functions and Graphs
4.8 Functions and Relations
Relations and Functions
4.6 – Formalizing Relations and Functions
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
4-6 Formulizing Relations and Functions
7.4 Functions Designed by Skip Tyler.
Notes Over 4.2 Is a Solution Verifying Solutions of an Equation
Introduction to Functions
FUNCTION DEFINITION: A RELATION IN WHICH EACH ELEMENT OF THE DOMAIN IS PAIRED WITH EXACTLY ONE ELEMENT OF THE RANGE. IN OUR OWN WORDS THIS MEANS ALL X-VALUES.
Identifying functions and using function notation
1-1 RELATIONS & FUNCTIONS
1.7 Represent Graphs as Functions
Functions FUNCTIONS AND THEIR GRAPHS Essential Questions:
Relations vs. Functions Function Notation, & Evaluation
Functions Introduction.
Boise State University
Find the Inverse and Graph the Functions
Objectives The student will be able to:
3-2 Representing Functions
Warm Up Given y = –x² – x + 2 and the x-value, find the y-value in each… 1. x = –3, y = ____ 2. x = 0, y = ____ 3. x = 1, y = ____ –4 – −3 2 –
10.1 Graphs and Graph Models
Chapter 5: Relations & Functions
College Algebra Chapter 2 Functions and Graphs
9.2 Representing Linear Functions
Relations and Functions
Functions.
Objective - To graph ordered pairs.
Topic 3: Relations, Functions, Function Behavior Lesson 15 (1.7)
4.8 Functions and Relations
Introduction to Functions
Graphs G = (V, E) V are the vertices; E are the edges.
The Coordinate Plane pg
Objectives The student will be able to:
2.1: Relations and Functions
3.5 – Introduction to Functions
Functions and Relations
Functions MATHPOWERTM 11, WESTERN EDITION
Objectives The student will be able to:
Dependent Axis Y Answer Output Range f (x) Function Notation
Objectives The student will be able to:
Relation (a set of ordered pairs)
I can determine whether a relation is a function
Line Graphs.
Domain-Range f(x) Notation
Presentation transcript:

Graphs: basic definitions and notation Definition A (undirected, unweighted) graph is a pair G = (V, E), where V = {v 1, v 2,..., v n } is a set of vertices, and E <= V 2, where V 2 = {{v 1, v 2 }, {v 1, v 3 },..., {v 1, v n },..., {v n-1, v n }} is an unordered product of V, i.e. a set of all two element subsets of V defining the set of all possible edges of the graph, G. Example G = (V, E) where V = {a, b, c, d} and E = V 2 a b d c c d a b Definition Graph G = (V, E) with all possible edges present (i.e. E = V 2 ) is called a complete graph.

Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities. CHG SF HTD OAK ATL LA SD V = {SF, OAK, CHG, HTD, ATL, LA, SD} E = {{SF, HTD}, {SF, CHG}, {SF, LA}, {SF, SD}, {SD, OAK}, {CHG, LA}, {LA, OAK}, {LA, ATL}, {LA, SD}, {ATL, HTD}, {SD, ATL}}

Definition A subgraph of a graph G = (V, E) is a graph G’ = (V’, E’), where V’<= V and E’<= E. Definition A graph with a small number of edges present ( E <= V log V) is called a sparse graph. Definition A graph with E > V log V is called a dense graph. Definition Let G = (V, E), and x, y are two vertices. We say that: x and y are adjacent if {x, y} belongs to E; x and y are called incident to the edge {x, y} (for brevity, we will write xy instead of {x, y}). To describe the relationship of adjacency in a graph, we use adjacency matrix. Let V = {a, b, c, d, e, f, g} and E = {ab, cd, fg, bg, af}. The adjacency matrix describing this graph is the following: a b c d e f g a b c d e f g we assume that vertices cannot be adjacent to themselves

Definition Let G = (V, E), and v 1,..., v n belong to V are such that v i v i+1 belongs to E for 1 <= i <= n-1. Then, the sequence v 1, v 1 v 2, v 2, v 2 v 3, v 3, v 3 v 4,..., v n-1, v n-1 v n, v n is called: a walk from v 1 to v n. We will write for brevity v 1 v 2 v 3... v n ; if the edges are all distinct, we call it a trail from v 1 to v n ; if the vertices are all distinct (except possible for v 1 and v n ), it is called a path between v 1 and v n ; a walk, trail or path is called trivial if it consists of a single vertex, otherwise it is called non-trivial; a walk, trail or path is called closed if v 1 = v n, otherwise it is called open; a non-trivial closed trail or path is called a cycle. Definition A graph is called connected if there is a path from each node to every other node in the graph.

Definition Let G = (V, E) be a connected graph, and T = (V, E’) be a tree with the same vertex set, V, but E’ is a subset of E. Then T is called a spanning tree of G. Example: a graph and its spanning tree

The Graph ADT Definition A graph, G, is a data structure comprised by two sets of objects, nodes and edges, where nodes store data and edges indicate relationships between the data stored in the nodes. Operations (methods) on graphs: addEdge(v1, v2) Returns G with new edge v1v2 added removeEdge(v1, v2) Returns G with edge v1v2 removed edge(v1, v2) Returns true if there is an edge between v1 and v2 vertices() Returns an enumeration all vertices in G edges() Returns an enumeration of all edges in G numVertices() Returns the number of vertices in G numEdges() Returns the number of edges in G degree(v) Returns the degree of v adjacentVertices(v) Returns an enumeration of the vertices adjacent to v incidentEdges(v) Returns an enumeration of edges incident to v

Representation of graphs as an adjacency matrix The easiest way to represent a graph is by means of its adjacency matrix. For unweighted undirected graphs, the adjacency matrix V(v ij ) is an n x n matrix, where 1, if v i v j belongs to E v ij = 0, otherwise for 1 <= i, j <= n, and v i v i belongs to E for all i. Example Consider the following graph  a  b mm  l  k  j  i  h  d  e  f  g  c

Example (contd.) The adjacency matrix of the example graph is the following: a b c d e f g h i j k l m a b c d e f g h i j k l m Because v i v i belongs to E for all i.

Representation of graphs as adjacency lists Each node has an adjacency list associated with it, which contains all of the nodes adjacent to that node. Our example graph is described by means of the following adjacency lists: a b c d e f g h i j k l m Here edges were assumed to have appeared in the following order: ag, ab, ac, lm, jm, jl, jk, ed, fd, hi, fe, af, ge.  f  a  f  e  a  g  j  k  h  i  b  c  j  f  e  g  d  e  d  m  l  a  l  m

Graph traversals Given graph G, we want to systematically visit every node, and check every edge. The two main traversals are: 1Depth-first traversal. Assume start is a node in the graph, where our traversal begins. Then, each node reachable from start is visited in the following order: 1)start is visited, then 2)the first node adjacent to start, and recursively all nodes adjacent to that node, then 3)the second node adjacent to start, and recursively all nodes adjacent to that node, then... 7)the n-th node adjacent to start, and recursively all nodes adjacent to it.

Graph traversals (contd.) 2Breadth-first traversal. Assume start is a node in the graph, where our traversal begins. Then, each node reachable from start is visited in the following order: 1)start is visited, then 2)all nodes adjacent to start, then 3)all nodes adjacent to the nodes adjacent to start, etc. Example: Assume the edges arrive in the following order: ad, ac, ab, bc, bd. Let the start node be a. b is the first node adjacent to a, and d is the first node adjacent to b. Then the depth-first traversal visits the nodes in the following order: a, b, d, c. The breadth-first traversal visits the nodes as follows: a, b, c, d given that b is the first node adjacent to a, c is the second node adjacent to a, and d is the third node adjacent to a. That is, traversals depend on assumptions about node connections.  c  b  a  d

Depth-first traversal: the algorithm Algorithm depthFirstTraversal (G, start) Input: a graph, G, and a node, start, in G. Output: all nodes in G visited. boolean[] visited = new boolean[numberOfNodes] for k := 1 to numberOfNodes visited[k] := false searchFrom(start,visited) Algorithm searchFrom (node, visited) Input: a node, start, in a graph. Output: start and all nodes reachable from start marked as visited. start.displayGraphNode() visited[start] := true for k := 1 to numberOfNodes if (! visited[k] && start.edge(k)) searchFrom(k,visited)

Breadth-first traversal: the algorithm Algorithm breadthFirstTraversal (G, start) Input: a graph, G, and a node, start, in G. Output: all nodes in G visited. boolean[] inQueue = new boolean[numberOfNodes] Queue nodesToVisit = new Queue(numberOfNodes) for k := 1 to numberOfNodes inQueue[k] = false nodesToVisit.enqueue(start) inQueue[start] = true while (! nodesToVisit.empty()) graphNode node = nodesToVisit.dequeue() node.displayGraphNode() for k:=1 to numberOfNodes if (! inQueue[k] and node.edge(k)) nodesToVisit.enqueue(k) inQueue[k] := true