GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
139 views
What is the time complexity to implement Dijkstra’s algorithm using a sorted array instead of heap for a Priority Queue?

for sorted array

let V be the number of nodes and E be the number of edges

1)extract min operation ---it will take constant time and it is repeated for V nodes.hence takes O(v) time.

2)decrease key operation occurs E times------now we can directly go and decrease the value of the node but we might have to sort the array again because after decreasing the key,array might not be sorted..so it will take VlogV time if we use merge sort.so ,total time is E*VLOGV

 

please verify this.
asked in Algorithms by Veteran (13k points)   | 139 views
it will be $O(v^3)$..
how..?can you tell whats wrong in my explanantion

http://stackoverflow.com/questions/2680365/running-time-for-dijkstras-algorithm-on-a-priority-queue-implemented-by-sorted

in this post,i saw it is also written that it is O(v^3) but tell me one thing,,after decreasing a particular key,dun w need to sort the array again cuz it might get unsorted..?

@Akriti

A small nitpick - You needn't to sort the whole array, just apply binary search and place the key there and shift the elements to a new position -> O(E.V) -> Now, the graph can either be sparse or complete.
ooh alright..thanks kapil..
exactly kapil ... that's what I was doing ... now uploaded !

1 Answer

+8 votes
Best answer

................

 

answered by Veteran (47k points)  
selected by
wonderful and clear explanation..thanks a lot ..:-)
@debashish deka  you are  next RAVI SHANKAR MISHRA ...wonderful explanation


Top Users May 2017
  1. akash.dinkar12

    3292 Points

  2. pawan kumarln

    1652 Points

  3. sh!va

    1650 Points

  4. Arjun

    1424 Points

  5. Bikram

    1372 Points

  6. Devshree Dubey

    1272 Points

  7. Debashish Deka

    1142 Points

  8. Angkit

    1044 Points

  9. LeenSharma

    904 Points

  10. srestha

    718 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. Bikram

    458 Points

  2. Arnab Bhadra

    402 Points

  3. pawan kumarln

    278 Points

  4. Ahwan

    236 Points

  5. bharti

    194 Points


22,786 questions
29,121 answers
65,184 comments
27,661 users