Slide 1

Slide 1 text

Milda Glebauskaitė Graph theory and software engineering

Slide 2

Slide 2 text

PART 1: Basics a.k.a stuff I should have learned in the university but I wasn’t listening

Slide 3

Slide 3 text

ORIGINS

Slide 4

Slide 4 text

ORIGINS

Slide 5

Slide 5 text

ORIGINS ● There should not be any uncrossed bridges ● Each bridge must not be crossed more than once.

Slide 6

Slide 6 text

ORIGINS ● There should not be any uncrossed bridges ● Each bridge must not be crossed more than once.

Slide 7

Slide 7 text

ORIGINS ● 4 lands, 7 bridges ● There are an odd number of bridges connected to each land ● if you enter a land by crossing one bridge, you can always leave the land by crossing its second bridge. If third bridge appears, you won’t be able to leave a land.

Slide 8

Slide 8 text

ORIGINS ● If new bridge appears, you can can solve the problem

Slide 9

Slide 9 text

ORIGINS ● If new bridge appears, you can can solve the problem

Slide 10

Slide 10 text

ORIGINS

Slide 11

Slide 11 text

ORIGINS Vertex Edge

Slide 12

Slide 12 text

ORIGINS Degree of a vertex, the number of edges incident connected to the vertex.

Slide 13

Slide 13 text

ORIGINS An Euler path of a finite undirected graph G(V, E) is a path such that every edge of G appears on it once. If G has an Euler path, then it is called an Euler graph.

Slide 14

Slide 14 text

ORIGINS Theorem. A finite undirected connected graph is an Euler graph if and only if exactly two vertices are of odd degree or all vertices are of even degree. In the latter case, every Euler path of the graph is a circuit, and in the former case, none is.

Slide 15

Slide 15 text

Graph representation

Slide 16

Slide 16 text

Graph representation Twitter problem

Slide 17

Slide 17 text

Graph representation

Slide 18

Slide 18 text

Graph representation

Slide 19

Slide 19 text

Graph representation

Slide 20

Slide 20 text

Graph representation Adjacency list - each list describes the set of neighbors of a vertex in the graph

Slide 21

Slide 21 text

Graph representation

Slide 22

Slide 22 text

Graph algorithms Any processing done with graphs can be called “graph algorithm”

Slide 23

Slide 23 text

Graph algorithms Uber/Google Maps problem

Slide 24

Slide 24 text

Graph algorithms

Slide 25

Slide 25 text

Graph algorithms

Slide 26

Slide 26 text

Dijkstra’s algorithm Graph algorithms

Slide 27

Slide 27 text

Dijkstra’s algorithm 1) Mark all nodes unvisited. Create a set of all the unvisited nodes called the unvisited set. 2) Assign to every node a tentative distance value: set it to zero for our initial node and to infinity for all other nodes. Set the initial node as current. Graph algorithms

Slide 28

Slide 28 text

Dijkstra’s algorithm 1) Mark all nodes unvisited. Create a set of all the unvisited nodes called the unvisited set. 2) Assign to every node a tentative distance value: set it to zero for our initial node and to infinity for all other nodes. Set the initial node as current. Graph algorithms

Slide 29

Slide 29 text

Dijkstra’s algorithm 3) For the current node, consider all of its unvisited neighbors and calculate their tentative distances through the current node. Compare the newly calculated tentative distance to the current assigned value and assign the smaller one. Graph algorithms

Slide 30

Slide 30 text

Dijkstra’s algorithm 4) When we are done considering all of the neighbors of the current node, mark the current node as visited and remove it from the unvisited set. A visited node will never be checked again. Graph algorithms

Slide 31

Slide 31 text

Dijkstra’s algorithm 5) If the destination node has been marked visited (when planning a route between two specific nodes) or if the smallest tentative distance among the nodes in the unvisited set is infinity (when planning a complete traversal; occurs when there is no connection between the initial node and remaining unvisited nodes), then stop. The algorithm has finished. 6) Otherwise, select the unvisited node that is marked with the smallest tentative distance, set it as the new “current node”, and go back to step 3. Graph algorithms

Slide 32

Slide 32 text

Dijkstra’s algorithm 5) If the destination node has been marked visited (when planning a route between two specific nodes) or if the smallest tentative distance among the nodes in the unvisited set is infinity (when planning a complete traversal; occurs when there is no connection between the initial node and remaining unvisited nodes), then stop. The algorithm has finished. 6) Otherwise, select the unvisited node that is marked with the smallest tentative distance, set it as the new “current node”, and go back to step 3. Graph algorithms

Slide 33

Slide 33 text

PART 2: Graphs are fun a.k.a stuff I found interesting but did not know how to structure into proper presentation

Slide 34

Slide 34 text

GT in Model based testing Model based testing is a software testing technique where run time behavior of software under test is checked against predictions made by a model. A model is a description of a system's behavior.

Slide 35

Slide 35 text

MBT ▪ You create model of a SUT ▪ It’s a simplified model ▪ It’s a state model defining states and relationships between them ▪ From this model you can generate tests and execute them on SUT

Slide 36

Slide 36 text

GT in MBT ▪ Chinese postman problem solutions ▪ de Bruijn sequences algorithm ▪ Random Walk algorithm

Slide 37

Slide 37 text

Graph coloring problem Given m colors, find a way of coloring the vertices of a graph such that no two adjacent vertices are colored using same color.

Slide 38

Slide 38 text

Real life problems ▪ Schedules and timetables ▪ Map coloring ▪ Sudoku

Slide 39

Slide 39 text

More fancy problems ▪ Register allocation

Slide 40

Slide 40 text

In compiler optimization, register allocation is the process of assigning a large number of target program variables onto a small number of CPU registers.

Slide 41

Slide 41 text

Nodes in the graph represent live ranges (variables, temporaries, virtual/symbolic registers) that are candidates for register allocation. Edges connect live ranges that interfere , i.e., live ranges that are simultaneously live at at least one program point. Register allocation then reduces to the graph coloring problem in which colors (registers) are assigned to the nodes such that two nodes connected by an edge do not receive the same color.

Slide 42

Slide 42 text

More fancy problems ▪ Register allocation ▪ Network updates

Slide 43

Slide 43 text

OO programs as graphs

Slide 44

Slide 44 text

GT in OO programs ▪ Identification of “God” classes - HyperLink Induced Topic Search algorithm

Slide 45

Slide 45 text

Hyperlink-Induced Topic Search is a link analysis algorithm that rates Web pages. The scheme assigns two scores for each page: its authority, which estimates the value of the content of the page, and its hub value, which estimates the value of its links to other pages.

Slide 46

Slide 46 text

GT in OO programs ▪ Identification of “God” classes - HyperLink Induced Topic Search algorithm ▪ Design pattern detection - graph matching algorithms

Slide 47

Slide 47 text

Thank You

Slide 48

Slide 48 text

P.S. I stole the illustrations from this post ▪ https://www.freecodecamp.org/news/i-dont-understan d-graph-theory-1c96572a1401/