Prim's Algorithm Time Complexity

前端 未结 3 815
悲哀的现实
悲哀的现实 2021-01-11 23:17

I was looking at the Wikipedia entry for Prim\'s algorithm and I noticed that its time complexity with an adjacency matrix is O(V^2) and its time complexity with a heap and

3条回答
  •  猫巷女王i
    2021-01-12 00:04

    From the Introduction to Algorithms (Carmen)

    Time= Θ(V)·T(EXTRACT-MIN) + Θ(E)·T(DECREASE-KEY)

                       T(EXTRACT-MIN)   T(DECREASE-KEY)   Total
    
    1. array            O(V)             O(1)              O(V^2)
    2. binary heap      O(lgV)           O(lgV)            O(E lgV)
    3. Fibonacci heap   O(lgV)           O(1)              O(E + VlgV)
    

    Using different data structures causes different time complexities.

提交回复
热议问题