We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4adb4b7 commit 75eda4bCopy full SHA for 75eda4b
09-problems/lc_787_cheapest_flights_within_k_stops.py
@@ -21,11 +21,10 @@
21
22
2. Intuition:
23
- Naive:
24
- - Kind of BFS + Optimizations:
+ - Kind of BFS + Optimizations: O(|V|^2 + |V||E|) ?
25
- to have a variable dst cheapest path price (initialized to Infinity)
26
- To visit cities multiple-times: when curr visit path price < prev visit path price
27
- To stop a path if its price > dst cheapest path price
28
- - Each node
29
- We could do better:
30
31
3. Implementation
@@ -39,9 +38,9 @@
39
38
40
class Solution_BFS:
41
'''
42
- Time Complexity:
+ Time Complexity: O(|V|^2 + |V||E|)
43
T = T(Build Adjacency List) + T(Kind Of BFS algo)
44
- = O(|E|)
+ = O(|E|) + |V| * O(|V| + |E|)
45
46
Space Complexity: O(|V| + |E|)
47
S = S(Adjacency_list) + S(BFS Curr Level Queue) + S(BFS Next Level Queue) + S(Visited Hash Map)
0 commit comments