Understanding Time complexity calculation for Dijkstra Algorithm

前端 未结 5 443
囚心锁ツ
囚心锁ツ 2020-12-12 11:17

As per my understanding, I have calculated time complexity of Dijkstra Algorithm as big-O notation using adjacency list given below. It didn\'t come out as it was supposed t

5条回答
  •  执笔经年
    2020-12-12 11:52

    Let's try to analyze the algorithm as given in CLRS book.

    for each loop in line 7: for any vertex say 'u' the number of times the loop runs is equal to the number of adjacent vertices of 'u'. The number of adjacent vertices for a node is always less than or equal to the total number of edges in the graph.

    If we take V (because of while loop in line 4) and E (because of for each in line 7) and compute the complexity as VElog(V) it would be equivalent to assuming each vertex has E edges incident on it, but in actual there will be atmost or less than E edges incident on a single vertex. (the atmost E adjacent vertices for a single vertex case happens in case of a star graph for the internal vertex)

提交回复
热议问题