Download presentation

Presentation is loading. Please wait.

Published byTori Balis Modified about 1 year ago

1
Introduction to Graph “theory” Why do we care about graph theory in testing and quality analysis? –The “flow” (both control and data) of a design, within a program or among programs may be depicted with a graphical representation. Graph gives us the tool to formally study these graphical representations of flow and design test cases from the flow.

2
What is a graph ? n2 n1 n3 n5 n4 n6 A graph, G = { N, E }, is composed of : i) a set of nodes, N, and ii) a set of edges, E, which connects the nodes. n7 e1 e5 e3 e4 e2 For the above example, N = { n1, n2, n3, n4, n5, n6, n7 } and E = {e1, e2, e3, e4, e5 }

3
Degree of a node Note that in the previous graph, not every node is immediately connected to another node; and some node is immediately connected to more than one other node. –For example: N7 is not connected to any other node N3 is connected to three other nodes: n1, n4 and n5. Formally, the “degree” of a node x, n x, is defined as the number of edges, e’s, that have node n x as the immediate end point. –This is the same as the number of other nodes that n x is immediately connected to Degree (n7) = 0 Degree (n3) = 3 For clarity, the definition uses edges, rather than immediately connect nodes.

4
Using Incidence matrix to represent graph n1 n2 n3 n4 n5 n6 n7 e1e2e3e4e An incidence matrix of a graph composed of J nodes and K edges is a J x K cross-product relation, where the rows are the nodes and the columns are the edges. The relation, in this case, is “immediately connected.” For this example, the incidence matrix represents a 7 x 5 cross-product relation. The 1 in a cell, (x,y) represents that node, n x, is the end point of edge, e y. The empty cells may be filled with 0’s. 1)The sum of 1’s for any row, which represents a node, is the degree of that node. - e.g. sum of 1’s for node, n5, is 2; therefore degree(n5) = 2 2)Each column shows the edge, e x, and the 1’s in that column shows the nodes that edge, e x, connects (note each column always adds up to 2.)

5
Using Adjacency matrix to represent graph n1 n2 n3 n4 n5 n6 n7 n1n2n3n n5n6n7 An adjacency matrix of a graph composed of Z number of nodes is a Z x Z relation where the rows are nodes and the columns are also nodes. Again the relation is “immediately connected.” For this example, the adjacency matrix represents a 7 x 7 cross-product relation. The 1 in a cell, (x,y) represents that node, n x, is immediately connected to another node, n y. The empty cells may be filled with 0’s. 1)The sum of 1’s for any row or any column is the degree of that node. - e.g. sum of 1’s for node, n3, is 3; thus degree(n3) = 3 2)Note that the matrix is symmetric across the diagonal.

6
Path Note that we used the term, “immediately connected” for degree of a node. A path in a graph is a sequence of immediately connected nodes: e.g. {n i, -- -, n j+z } in the graph where n j is immediately connected to n j+1, and node n j+1 is immediately connected to n j+2, and so on to node n j+z. A path in a graph may also be defined as a sequence of edges, such that for any pair of edges, e i and e j, in the sequence, the edges share a common node.

7
Paths n2 n1 n3 n5 n4 n6 n7 e1 e5 e3 e4 e2 There are several paths in the example graph. node sequence to depict a path edge sequence to depict a path Path1 : n2, n1, n3, n5 e1, e2, e4 Path2 : n1, n3, n4 e2, e3 You may use either approach; I may mix and use both

8
Connected nodes Earlier two nodes are said to be immediately connected if there is an edge that connect the two nodes. The degree of a node was determined by the number of its immediately connected nodes. Now a more general notion of connectedness of two nodes may be given. Node n x is connected to node n y if there is a path from n x to n y

9
Properties of Connectedness Connected nodes on a path have some interesting relational properties: –It is reflexive because every node is connected to itself and thus is on the same path. –It is symmetric because nodes n i and n j on a path implies that nodes n j and n i are also on the same path. –It is transitive for nodes n i and n j on a path and nodes n j and n k on the same path implies that n i and n k are on the same path also. Note: This relation of ‘connected’ satisfies the definition of equivalence relation.

10
Component and condensation graph A component of a graph is defined as the maximal set of connected nodes. –From our graph example: {n1, n2, n3, n4, n5, n6} form a component {n7} also forms a component A condensation graph is formed by replacing each component in the original graph by a “condensed” single node. There are no edges. –Condensation graph of a graph gives us a view of the “complexity” through the number of components.

11
Condensed Graph n2 n1 n3 n5 n4 n6 n7 e1 e5 e3 e4 e2 N1N2 From design/coding/testing perspective, this says we have two major “chunks” or components that we need to worry about.

12
Directed Graph n2 n1 n3 n5 n4 n6 n7 e1 e5 e3 e4 e2 A directed graph, DG = { N, E }, is composed of : i) a set of nodes, N, and ii) a set of edges, E, which connects the nodes in “order” (the set of edges have directions) For example: e1 does not only connect nodes n2 and n1, but shows that the order is n1 to n2. Thus e1 may viewed as an ordered tuple,, which is different from.

13
Degrees of Directed Graph With directed graph, one can utilize the directional concept. –e.g. the flow of a program, the control flow in imperative programming language, can be represented by directed graph. –Each edge not only connects nodes but shows a direction (like a vector). For each node, n, in the graph, there may be defined: 1.Indegree (n) = the number of distinct edges immediately directed in and towards n. 2.Outdegree (n) = number of distinct edges immediately directed out and away from n. Note that for any node, n: degree (n) = indegree (n) + outdegree (n)

14
Some “types” of node for directed graph Source node is a node with indegree = 0. Sink node is a node with outdegree = 0. Transfer node is node with indegree ≠ 0 and outdegree ≠ 0. n2 n1 n3 n4 n4 is a source node. n1 and n2 are transfer nodes. n3 is a sink node.

15
Adjacency Matrix for Directed Graph n2 n1 n3 n4 n1 n2 n3 n4 n1n2n3n ) There is a directed edge from n4 to n1. Thus there is a 1 in cell (4,1). 2) There is a 1 in cell (1,2) to indicate that there is a directed edge from n1 to n2. 3) And finally, the 1 in cell (2,3) represents the directed edge from n2 to n3 ‘from’ nodes ‘to’ nodes

16
Path and semi-path With directed graph, the notion of a path is not just connection, but there is a directional connection. –1. A directed path is a sequence of edges such that for any adjacent pair of edges, e1 and e2, the terminal node for e1 is the starting node for e2. –2. a cycle is a directed path that begins and ends at the same node –3. A directed semi-path is a sequence of edges such that, for at least one adjacent pair of edges, ei and ej, in the sequence, the initial node of the first edge is the same initial node of the second edge or the terminating node of the first edge is the same as the terminating node of the second edge.

17
Path, cycle, and semi-path n2 n1 n3 n4 Note that we linked n2 to n4 to create a cycle 1.There is a directed path from n1 to n3. 2.There is cycle “among” n1, n2, and n4. 3.There is a directed semi-path between n3 and n4

18
Reachability with Adjacent Matrix Operations Adjacent matrix for a directed graph indicates the directional connection of the nodes, not a two way connection. Note that an edge that connects nodes, nx and ny does not mean it connects ny and nx in the reverse way. So for directed graph the “connect” operation is non-symmetric. We can use matrix operation on Adjacent matrix of the directed graph to view the paths in the directed graph.

19
An example of operating on Adjacent matrix for directed graph n2 n1 n3 n4 n1 n2 n3 n4 n1n2n3n A 1 = A 2 = X= Note that A 1 gives connections length 1, and A 2 gives the connections of length 2 in the directed graph.

20
More on Adjacent Matrix operation of A3=A3= =XX A4=A4= = X XX A 3 shows only one path, from n4 to n3, that is length 3 in the directed graph A 4 shows that there is no length 4 path in the directed graph

21
Reachability of directed graph using Adjacent matrices n2 n1 n3 n4 - Assuming that every node can reach itself, we will not indicate the reachability of a node to itself. -Reachability, R, of a directed graph may be derived from the adjacency matrix, A, of that directed graph as follows: R = A 1 + A A k, where A k is non-zero, but A k+1 is zero R = R = = A 1 + A 2 + A If you were interested in a variable or a constant that is defined in one node and where it could “possibly” be used ---- this may help

22
Graph Representations Will need these later: Program Control Flows: sequential, if-then-else, loop, etc. State Transition Diagram (Finite State Machines): states and stimuli Will not use: Petri Net: a complex set of events and transitions State Charts: A complicated (embedding of states) form of State Transition Diagram

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google