Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Graph theory and software engineering it1

Milda
March 06, 2020
56

Graph theory and software engineering it1

Milda

March 06, 2020
Tweet

Transcript

  1. Milda Glebauskaitė
    Graph theory and software
    engineering

    View Slide

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

    View Slide

  3. ORIGINS

    View Slide

  4. ORIGINS

    View Slide

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

    View Slide

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

    View Slide

  7. 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.

    View Slide

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

    View Slide

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

    View Slide

  10. ORIGINS

    View Slide

  11. ORIGINS
    Vertex
    Edge

    View Slide

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

    View Slide

  13. 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.

    View Slide

  14. 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.

    View Slide

  15. Graph representation

    View Slide

  16. Graph representation
    Twitter problem

    View Slide

  17. Graph representation

    View Slide

  18. Graph representation

    View Slide

  19. Graph representation

    View Slide

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

    View Slide

  21. Graph representation

    View Slide

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

    View Slide

  23. Graph algorithms
    Uber/Google Maps problem

    View Slide

  24. Graph algorithms

    View Slide

  25. Graph algorithms

    View Slide

  26. Dijkstra’s algorithm
    Graph algorithms

    View Slide

  27. 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

    View Slide

  28. 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

    View Slide

  29. 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

    View Slide

  30. 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

    View Slide

  31. 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

    View Slide

  32. 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

    View Slide

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

    View Slide

  34. 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.

    View Slide

  35. 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

    View Slide

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

    View Slide

  37. 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.

    View Slide

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

    View Slide

  39. More fancy problems
    ▪ Register allocation

    View Slide

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

    View Slide

  41. 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.

    View Slide

  42. More fancy problems
    ▪ Register allocation
    ▪ Network updates

    View Slide

  43. OO programs as graphs

    View Slide

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

    View Slide

  45. 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.

    View Slide

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

    View Slide

  47. Thank You

    View Slide

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

    View Slide