← 回題庫

卷別

資料結構與演算法(A)

選擇

國立臺灣大學 2022 · 考試 · 第 20 題

考科演算法

(5 points) Given a graph G=(V,E)G = (V, E) with the adjacent matrix W=wijW = w_{ij} with WW an n×nn \times n matrix. The following algorithm can compute the All-Pairs Shortest Path of GG.

FLOYD-WARSHALL'(W)
1  D = W
2  for k = 1, 2, ..., n
3      for i = 1, 2, ..., n
4          for j = 1, 2, ..., n
5              d_ij = min(d_ij, d_ik + d_kj)

What is the SPACE complexity of this algorithm?

  • (A)
    Θ(n2)\Theta(n^2)
  • (B)
    Θ(n3)\Theta(n^3)
  • (C)
    Θ(n)\Theta(n)
  • (D)
    Θ(n4)\Theta(n^4)
  • (E)
    none of the other choices

標準解析

AI 生成