首页 > 解决方案 > 图算法的运行时间

问题描述

我对以下算法的运行时间计算有疑问我不确定我的答案,我想检查正确的答案

Algorithm Unknown(G)
Input: A weighted graph with n vertices, and m edges
Output: ?????
    P ← create array of size n to to referenced by vertix id number (id[u])
    Q ← create array of size n to to referenced by vertix id number.
    for each u ∈ G.vertices() do
        Q[id(u)] ← null
    for each v ∈ G.vertices() do
        for each u  G.vertices() do
            if G.areAdjacent(u,v) then
                P[id(u)] ← -∞
        for each u ∈ G.vertices() do
            for each e ∈ G.incidentEdges(u) do
                z ← G.opposite(u,e)
                if G.valueAt(e) > P[id(z)] then
                    P[id(z)] ← valueAt(e)
                    Q[id(z)] ← e
    return Q

标签: time-complexity

解决方案


推荐阅读