Can anyone tell me the space complexity of the priority queue in this Dijkstra algo. Note that here one vertex can be added to queue more than one time. However, due to the visited set it is not processed more than one time. This is why I am wondering the max size of the queue can get.
def shortestReach(n, edges, start,target):
adjList = collections.defaultdict(list)
for parent, child, cost in edges:
parent -= 1
child -= 1
adjList[parent].append((child, cost))
adjList[child].append((parent, cost))
priorityQueue = queue.PriorityQueue()
priorityQueue.put((0, start))
visited = set()
while priorityQueue.qsize() > 0:
costPar, parent = priorityQueue.get()
if parent == target:
return costPar
if parent not in visited:
for adj in adjList[parent]:
child, cost = adj
priorityQueue.put((cost + costPar, child))
visited.add(parent)