Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graphs and Sets Dr. Andrew Wallace PhD BEng(hons) EurIng

Similar presentations


Presentation on theme: "Graphs and Sets Dr. Andrew Wallace PhD BEng(hons) EurIng"— Presentation transcript:

1 Graphs and Sets Dr. Andrew Wallace PhD BEng(hons) EurIng andrew.wallace@cs.umu.se

2 Overview Sets Implementation Complexity Graphs Constructing Graphs Graph examples

3 Sets Collection of items No specified ordered Unique values Implementation of mathematical concept of finite set Static of dynamic

4 Sets

5 Examples: int, float, char Arrays Functions Objects (struct)

6 Set operations Create Insert Remove Is member of Is empty Select Size of Enumerate

7 Implementation Simple Array List Efficient Trees Radix trees Hash tables

8 Implementation Insert Check for duplicates Union If list has duplicates Check when doing Equal Remove Intersection Difference

9 Implementation

10 Bit field struct bField { int: 6; intm_nVal1: 3; intm_nVal2: 4; int m_nVal3 : 6; }

11 Implementation Limitations Can’t use bit field variables in an array Can’t take the memory address of a bit field variable Can’t overlap integer boundaries

12 Implementation Priority Queues Linux kernel Caching algorithms / memory pages

13 Complexity Depends on implementation Improve set operations such as union or intersection Improve insert, search, remove O(n) or O(logn) Some set operations can take O(m*n)

14 Graphs Set of nodes or vertices + pairs of nodes G = (V, A) Directed or undirected Undirected a to b is the same as b to a Node - undirected Vertices - directed Edge Arcs (directed) Connection between nodes Weighted or unweighted a c b d

15 Graphs V = {a, b, c, d} A = {(a, b), (a, c), (b, d), (c, b)} Adjacency 2 edges are adjacent if the share a common vertex (a, c) and (a, b) 2 vertices are adjacent if they share a common edge a and c Join Incident An edge and vertex on the edge a c b d

16 Graphs struct Node { int nNodeID; Node*pOut; intnOut; };

17 Graphs struct Edge { int nEdgeID; intnStart; intnEnd; };

18 Graphs Trivial graph One vertex Edgeless graph Vertices and no edges Null graph Empty set

19 Graphs Paths Sequence of nodes {a, b, d} Simple path No repetition of nodes Cyclic path Around and around in circles! Walk Open walk = path Closed walk = cyclic path Trail = walk with unique edges a c b d

20 Graphs Connected graph All nodes have a path to all other nodes Sub graphs Vertices are a sub set of G Adjacency relationship are a subset of G’s and restricted to the subgraph Complete graph All nodes connected to all other nodes Undirected graph A = n(n-1)/2 If A < n-1, then the graph is not connected a c b d c b a

21 Graphs Weighted graphs Maps Places as node Roads as arcs Distances as weights on the edges

22 Graphs Weights can represent “cost” Some algorithms require restrictions on weights Rational numbers or integers All positive integers Weight of a path Sum of the weights for a given path a c b d 10 20 23 13

23 Constructing Graphs Adjacency lists An array of arrays of adjacent vertices a c b d a b d c cb d b

24 Constructing Graphs int**pNodeArray; pNodeArray = (int**)malloc(sizeof(int) * 10); for(i=0;i<10;i++) { pNodeArray[i] = malloc(sizeof(int) * NumNodesOut[i]); } pNodeArray[i][j] = nNodeOut;

25 Constructing Graphs Adjacency matrix Node x node matrix (n x n) a c b d 11 1 1

26 Constructing Graphs Undirected graph symmetrical a c b d 11 1 1 11 1 1

27 Constructing Graphs int**pNodeArray; pNodeArray = (int**)malloc(sizeof(int) * 10); for(i=0;i<10;i++) { pNodeArray[i] = malloc(sizeof(int) * 10); } pNodeArray[i][j] = 1;

28 Graph examples Robot navigation AGV (automatic Guided Vehicles) Free space paths Pick up and drop off points Map as a graph

29 Graph example

30 Computer Networks

31 Questions?


Download ppt "Graphs and Sets Dr. Andrew Wallace PhD BEng(hons) EurIng"

Similar presentations


Ads by Google