• retagged by
472 views
0 0 votes

What is the Time Complexity of the Dijkstra when it is using Adjacency list + Array (sorted or unsorted ) ? 
If it is O( V^2 + E ) then ,
According to the General form of Adj. List :  V T(remove min) + E T(update key ) 
if we are Using Sorted Array 

  • Insert: O(V) 
  • Delete Min: O(1)
  • Update Key: O(V)   

if we are Using UnSorted Array 

  • Insert: O(1) 
  • Delete Min: O(n)
  • Update Key: O(V)    

So according to this Our Complexity should look like this : O(V^2  + E*V) . 
Please Resolve this Confusion . 
 

1 Answer

3 3 votes

Dijkshtra time complexity(considering adjacency list) = E(decrease key) + V(extract min)

On sorted array; 

Decrease key operation = O(V), we can directly update key but rearranging them might take O(V) time

Extract minimum= O(1), we can directly extract minimum as it was a sorted array

so modified version of Dijkshtra Algo time complexity = E(V) + V(1) = EV + V

now coming to a tricky part, we can clearly see time complexity depends upon edges and vertices so considering graph structure we have 2 choices,

  • Sparse graph where Number of edges E approaches V, E ≈ | V |
  • Dense graph where number of edges E approaches to V², E ≈ | V² |
let's update modified Dijkshtra Algo time complexity again by substituting values of E = EV + V
                                                                                                                                       = V².V + V = O(V³)
 
Dijlshtra Algo time complexity(Sorted Array + Adj List) = O(V³)
 
On Unsorted array;
 

Decrease key operation = O(1), directly go to array index and update, no need to rearrange here

Extract minimum= O(V), one full scan required

Dijkshtra time complexiy = E(1) + V(V) = O(E + V²)

Now again, considering graph structure we have 2 choices,

  • Sparse graph where number of edges E approaches V, E ≈ | V |
  • Dense graph where number of edges E approaches to V², E ≈ | V² |
Dijkshtra time complexiy(Unsorted Array + Adj list) = O(E + V²) = O(V² + V²) = O(V²)

 

 
 
 
 
 

 

Position:
Show:

Related questions

2 2 votes
1 1 answer
1.1k
1.1k views
Sahil Gupta asked Dec 16, 2014
1,114 views
if Dijkstra shorest path algorithm takes 8 second for a graph of 1000 nodes then approximatly how much time would it take for a graph of 1000000 nodes.a) 8000000 sec.b) 8...
1 1 vote
1 answers 1 answer
3.4k
3.4k views
iarnav asked May 22, 2018
3,361 views
Question Source - https://gateoverflow.in/1374/gate2005-38Let G(V,E)be an undirected graph with positive edge weights. Dijkstra’s single source shortest path algorithm ca...
0 0 votes
0 0 answers
819
819 views
gate20232 asked Jan 18, 2023
819 views
1 1 vote
3 answers 3 answers
4.7k
4.7k views
ankit_thawal asked Jan 25, 2018
4,657 views
I think answer should be Option(B).Path:<s,y><y,x><x,t = 7-3-2=2