그래프 최단경로 알고리즘 비교 & 대표문제

천호영·2022년 7월 16일
0

알고리즘

목록 보기
37/100
post-thumbnail

표로 정리

Single Source Shortest Path (SSSP)All-Pairs Shortest Paths (APSP)
Edge에 weight 없음Breadth First Search (BFS)Floyd-Warshall Algorithm
weight 있고, 음수 weight 없음Dijkstra AlgorithmFloyd-Warshall Algorithm
weight 있고, 음수 weight 있음Bellman-Ford AlgorithmFloyd-Warshall Algorithm

출처: https://shnoh.tistory.com/15

각각의 시간복잡도

V: vertex(정점) 수
E: Edge(간선) 수

  • Breadth First Search (BFS)
    • O(V+E)O(V+E) (인접리스트로 구현했을 때)
    • O(V2)O(V^2) (인접행렬로 구현했을 때)
  • Dijkstra Algorithm(Greedy기반)
    • O((V+E)logV)O((V+E)*logV) (우선순위큐 이용했을 때)
      => O(ElogV)O(E*logV) (모든 정점이 출발지에서 도달 가능하다면)
    • O(V2)O(V^2) (우선순위큐 이용 안 했을 때)
  • Bellman-Ford Algorithm
    • O(VE)O(V*E)
  • Floyd-Warshall Algorithm(DP기반)
    • O(V3)O(V^3)

관련 문제

(추가중)

profile
성장!

0개의 댓글