Presentation is loading. Please wait.

Presentation is loading. Please wait.

Concepts of Computation

Similar presentations


Presentation on theme: "Concepts of Computation"— Presentation transcript:

1 Concepts of Computation
Session 8a Graphs Dr Oded Lachish (Slides prepared with the support of Dr Paul Newman and Eva Szatmari)

2 Graphs Graphs What is a graph? Representation of graphs
Vertex degrees etc. Connectivity of graphs

3 Before we had Smart Phones and Navigation apps
We used a map. The map was usually very detailed and in big cities it took an effort to just find where you. Now we have smart phones. So instead of navigating with a map, we let the smart phone give us the instructions. Does the smart phone look at the map? Sort of

4 Computers and maps For a computer to take a look at a map requires a lot of effort. They don’t just see the whole picture, they have to look pixel by pixel. So just looking at a map like we used to, is too much. In reality, to navigate we don’t really need an exact map and it doesn’t need to have so much information. Have you tried walking from king cross St Pancras to Caledonian road just because they are close on the map (I did)

5 Underground map The underground map contains just the information required for navigating the underground. It is not good for navigating in London. The same idea is used in computers. What the computer stores as a “map” is only the information that is required for its purposes. Lets suppose that the purpose of the computer is to tell you how to go from one junction to another junction

6 Computer “maps” Lets suppose that the purpose of the computer is to tell you how to go from one junction to another junction What does the computer need to know: All the junctions All the roads between pairs of junctions and the junctions they are between (we assume that a road does not have junctions in the middle. This enables a cleaner mathematical definition later on) The length of the road Opening hours (The road through Hyde park is locked at night) And other stuff

7 Computer “maps” Lets suppose that the purpose of the computer is to tell you how to go from one junction to another junction Lets assume that at the beginning all the roads are always open and we only want the computer to find us a route, we don’t care if it the shortest route Now what does the computer need to know: All the junctions All the roads between pairs of junctions and the junctions they are between How do we do this mathematically. Sets

8 Computer “maps” and Sets
Now what does the computer need to know: All the junctions All the roads between pairs of junctions and the junctions they are between Lets have a set of all the junctions, call it V We also need a set for the roads. Lets call that set E. We don’t need the names of the roads, we just need the two junctions they are between (we assume no two roads are between the same two junctions). So, lets represent every road by a set of size 2, containing the two junctions it connects. Conclusion all the sets in E are subsets of V, each of size 2. We almost fully defined a graph. Graphs are very useful and studied. That’s why we formally define them in the next slide.

9 Graph Ordered, pair because the set on the left is
A graph (G) consists of two things: A set V, whose elements are called vertices A set E of unordered pairs (size two sets) of vertices, called edges The graph is denoted G=(V,E) Two vertices u and v in V are adjacent in G if and only if {u,v} ∈𝐸 Ordered, pair because the set on the left is the set of vertices and the set on the right is the set of edges.

10 Diagrammatic Representation
One dot for each vertex, v in V Each edge e = {v1,v2} represented by a line connecting v1 and v2 e4 v1 v4 V = {v1,v2 ,v3,v4} Edges: e1 = {v1,v2}, e2 = {v2,v3} e3 = {v3,v4}, e4 = {v1,v4} e5 = {v1,v3} e1 e3 e5 v2 v3 e2

11 Multigraphs etc. For every two vertices in a graph, there are one or zero edges connecting two vertices If we need more that one edge between the same two vertices v1 and v2 (parallel edges) we use a generalization of a graph called a multigraph. In a multigraph, we can also have loops, where a loop is an edge between a vertex and itself. A multigraph is finite if we have a finite number of edges and vertices. Remark: In a multigraph, V is a multi set. A multi-set is a generalization of a set in the sense that it allows elements to repeat and you can know how many time each element appears.

12 Multigraph example e6 e1 v1 v4 e2 e3 e4 v2 v3 e5

13 Subgraph G(V,E) is a graph.
If V’ is a subset of V and E’ is a subset of E whose endpoints belong to V’ Then G(V’,E’) is a subgraph of G(V,E) If E’ contains all the edges from E whose endpoints are in V’, then G(V’,E’) is the subgraph generated by V’

14 Subgraph example G1 = (V1, E1) v1 G = (V,E) v1 v4 v5 v2 v5 v3 v2 v1
G1=(V1, E1) is a subgraph of G but not an induced subgraph of G (missing {v1,v2} ) G2=(V2, E2) is a an induced subgraph of G G2 = (V2, E1) v1 v5 v2

15 Degree If v is an endpoint of edge e, then e is incident on v
The degree of vertex v, written deg(v), is the number of edges which are incident on v If deg(v) = 0, then the vertex is called isolated Each edge connects two vertices, so the sum of deg(v) is twice the number of edges A vertex is odd if and only if deg(v) is odd A vertex is even if and only if deg(v) is even

16 Example e4 v1 v2 e1 e3 v5 e5 v3 v4 e2 deg (v1) = 3, deg (v2) = 2, deg (v4) = 3, deg (v3) = 2, deg (v5) = 0 v2, v3 and v5 are even; v1 and v4 are odd v5 is isolated

17 Directed graphs A directed graph (or digraph) with direction assigned to each edge These directed edges are called arcs and denoted a = <u,v> for an arc connecting initial point u to terminal point v The outdegree, of a vertex v, is the number of arcs beginning at v, the indegree is the number of arcs ending a v A source has zero indegree; a sink has zero outdegree

18 Walk, Trail, Path A walk in a graph is a series of vertices linked with the edges connecting them. e.g. v0,e1,v1,e2,v2, …, en-1, vn-1, en, vn , where edge ei is incident on vi-1 and vi The number of edges, n, is the length of the walk A trail is a walk where all edges are unique (vertices can repeat, but edges cannot) A path is a walk where all vertices are unique with the exception that the first and last may be the same (a path is therefore also a trail)

19 Notation, Walk, Trail, Path
Formally describing a walk, trail and path is done using a tuple of only vertices. On the graph on the right The following is a walk (v1, v2, v3, v4, v2, v3) Which actually means: (v1,{v1, v2}, v2,{v2, v3}, v3, {v3, v4}, v4, {v4, v2}, v2, {v2, v3}, v3) If one of the edges was missing this is not a walk! v1 v2 v3 v4 v6

20 A circuit is a closed trail, except v0 = vn
A walk (v1, v2, …, vn) is closed if v1 = vn, otherwise the walk is from (or between or connects) v1 to vn A circuit is a closed trail, except v0 = vn A simple cycle is a path with the same first and last vertices A cycle of length k is called a k-cycle. The minimum value of k is 3. (v1, v2, …, vn )- this notation is used in order to indicate that we describing a general walk. What the first line means is that a walk is closed if and only if the first and the last vertices in the walk are the same.

21 Example v1 v2 v3 v4 v5 v6 (v4, v1, v2, v5, v1, v2, v3, v6)
Is a walk from, because all pairs of consecutive vertices correspond to an edge in the graph (you need to check this) It is not a trail, because {v1, v2} appears twice, It is not a path because it is not a trail (edges repeating means vertices repeating – in this case v1 and v2) It is not a closed walk, cycle or circuit, because the first and last vertices are different Length 7 The shortest path from P4 to P6 is (P4,P5,P6) which has length 2 This shows that by eliminated unnecessary edges, any walk from a vertex u to a vertex v can be replaced by a path from u to v

22 Example v1 v2 v3 v4 v5 v6 (v4, v1, v5, v2, v6) Is not a walk, because {v2, v6} is not an edge in the graph Is not anything else on the list, because it is not a walk Doesn’t have a length, because it is not a walk The shortest path from P4 to P6 is (P4,P5,P6) which has length 2 This shows that by eliminated unnecessary edges, any walk from a vertex u to a vertex v can be replaced by a path from u to v

23 Example v1 v2 v3 v4 v5 v6 (v4, v1, v5, v2, v3, v5, v6)
Is a trail, because all pairs of consecutive vertices correspond to an edge in the graph and no edge repeats itself Is a walk, because every walk is also a trail Is not a path because v5 repeats itself It is not a closed walk, cycle or circuit, because the first and last vertices are different Length 6 The shortest path from P4 to P6 is (P4,P5,P6) which has length 2 This shows that by eliminated unnecessary edges, any walk from a vertex u to a vertex v can be replaced by a path from u to v

24 Example v1 v2 v3 v4 v5 v6 (v4, v1, v5, v3, v6)
Is a path, because all pairs of consecutive vertices correspond to an edge in the graph and no vertex repeats itself Is a walk and trail, because every path is also a trail and a walk It is not a closed walk, cycle or circuit, because the first and last vertices are different Length 4 The shortest path from P4 to P6 is (P4,P5,P6) which has length 2 This shows that by eliminated unnecessary edges, any walk from a vertex u to a vertex v can be replaced by a path from u to v

25 Example v1 v2 v3 v4 v5 v6 (v1, v2, v3, v5, v2, v1)
Is a closed walk, because the first and last vertices are the same and all pairs of consecutive vertices correspond to an edge in the graph It is not a trail, because {v1, v2} repeats itself (remember, the order in the edge does not matter {v1, v2} = {v2, v1} ) Is not a path because it is not a trail Is not a circuit, because it is not a trail Is not a simple path because it is not a circuit Length 5 The shortest path from P4 to P6 is (P4,P5,P6) which has length 2 This shows that by eliminated unnecessary edges, any walk from a vertex u to a vertex v can be replaced by a path from u to v

26 Example v1 v2 v3 v4 v5 v6 (v4, v1, v2, v5, v4) is a simple cycle, because the first and last vertices are the same and all pairs of consecutive vertices correspond to an edge in the graph and only the first and last vertices are the same Is everything on the list, because it is a simple cycle Length 4 The shortest path from P4 to P6 is (P4,P5,P6) which has length 2 This shows that by eliminated unnecessary edges, any walk from a vertex u to a vertex v can be replaced by a path from u to v

27 Remember Every trail is a walk, but not every walk is a trail
Every path is a trail, but not every trail is a path Every circuit is a closed walk, but not every closed walk is a circuit Every simple cycle is a circuit. But not every circuit is a cycle A simple cycle is a path, but not every path is a simple cycle A circuit is a trail, but not every trail is a circuit A closed walk is a walk, but not every walk is closed

28 Connected graph There is a walk between vertices u and v if and only if there is a path from u to v A graph is connected if there is a path between any two of its vertices. The distance d(u,v), between two vertices u and v in a connected graph G, is the length of the shortest path between u and v The diameter of graph G is the maximum distance (the largest distance) between any two of its vertices

29 Examples d(v1, v6) = 2, d(v1, v4) = 1
Maximum distance possible is 2, so diameter = 2 The shortest path from P4 to P6 is (P4,P5,P6) which has length 2 This shows that by eliminated unnecessary edges, any walk from a vertex u to a vertex v can be replaced by a path from u to v


Download ppt "Concepts of Computation"

Similar presentations


Ads by Google