How to find a triangle inside a graph?

前端 未结 4 798
刺人心
刺人心 2021-01-31 18:05

Here is an exercise in the Algorithm Design Manual.

Consider the problem of determining whether a given undirected graph G = (V, E) contains a triangle

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-31 18:18

    I really like the matrix multiplication solution discussed in this blog post.

    Let a = the adjacency matrix

    • The adjacencies in a*a (a2) matrix multiplied are the numbers of 2-length paths
    • The adjacencies in a2*a matrix multiplied are the numbers of 3-length paths

    The problem is, matrix multiplication is slow... However, you can use GPGPU to perform matrix multiplication and can have a performant solution on modern architectures that include a GPU.

提交回复
热议问题