
Dijkstra's algorithm time complexity: O((V+E) log V)
Dijkstra's algorithm time complexity: O((V+E) log V)
Dijkstra's algorithm is designed to find the shortest paths in a weighted graph efficiently. The time complexity of O((V+E) log V) indicates that the algorithm's performance scales with the number of vertices (V) and edges (E) in the graph, as well as the efficiency of the priority queue used. This complexity is achieved by using a min-priority queue to repeatedly select the next node with the smallest tentative distance.
Example
In a graph with 5 vertices and 7 edges, Dijkstra's algorithm will perform a series of operations that involve selecting the shortest path from the source node to each of the other nodes. The priority queue helps to efficiently retrieve the next node to process, ensuring that the algorithm completes in O((V+E) log V) time.
Understanding the time complexity of Dijkstra's algorithm is crucial for evaluating its efficiency and scalability in real-world applications, such as network routing protocols.
Binary search
Time complexity of binary search: O(log n) — halves search space each step
Graph (abstract data type)
Time complexity of BFS and DFS: O(V + E)
merge sort: O(n log n) always
Merge sort consistently performs at O(n log n) time complexity for any input size
Best, worst and average case
Quicksort's average time complexity is O(n log n)
O(n log n) is the lower bound for comparison-based sorting
O(n log n) is the lower bound because each of n elements must be compared at least log n times to ensure all permutations are considered
Hash table
Hash table lookup: O(1) average time complexity
One email a day: 5 concepts + the 5 stories that matter →
Swipe through 100 ML concepts daily
Open TickerNews