XMORE's blog

By XMORE, history, 6 months ago, In English,

What is the complexity of dijkstra algorithm but without the vis array and without checking for dist array code https://ideone.com/VTaE03

 
 
 
 

»
6 months ago, # |
  Vote: I like it 0 Vote: I do not like it

What's the meaning of k in the code?

  • »
    »
    6 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    k is the total amount of money i have and each edge have cost and length cost is p and length is l

»
6 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

It can be quadratic, for example this directed graph:

Initial node is connected with k nodes (with cost 1), these k nodes are connected with another node (middle)(with costs k, k — 1 , k — 2..., 1). Middle node is connected with another k nodes (with cost 1), which are connected to the final node (with cost oo, a.k.a. big enough).

Certainly middle node will be visited k times, and visiting it requires k operations, as it has k neighbours. So total complexity would be at least .

  • »
    »
    6 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    If I understood the code correctly it wouldn't be difficult to construct O(2n) in a similar way.