Open 0WN463 opened 6 years ago
"5. O((V+E)LogE) Technically, we can convert EL to AL in O(V+E), then the complexity will be bounded as above" We aren't allowed to use additional data structures, sadly.
But they said no additional data struct. My reasoning was that you'd have to do O(V+E) anyway because of traversal. But then finding each edge would have you binary search for each query, so multiply by logV. What do you think?
"4. undirected, weighted, and may have negative weight cycle:" But it'll produce WA. That's the problem. What do you think?
"There is no input graph that can make Bellman Ford’s algorithm runs slower than O(V E). PS: The input graph has to be a simple graph without self-loop or multiple edges." Simple graph is assumed throughout the module. I'm not sure about this though. http://people.inf.elte.hu/hytruongson/Bellman-Ford/Bellman-Ford.html This source says BF is O(V^3) for AdjMatrix. I thought it's V^3 because you had to loop through to find the edges? I said O(V^2 + VE) because of V^2 for conversion to AdjList and VE for running BF.
The rest of the issues have been fixed/clarified. Thanks for your contribution :)
"5. O((V+E)LogE) But they said no additional data struct. My reasoning was that you'd have to do O(V+E) anyway because of traversal. But then finding each edge would have you binary search for each query, so multiply by logV. What do you think?
Hmm if that's the case, we would go to each vertex once, and at each vertex, we binary search for the source. So O(V log E). Once we found the source in the EL (assuming we sorted the EL by sources), we can just iterate through from that point onwards to get its neighbours. We would iterate all E edges once, so it should be O(V log E + E)?
Why would it be WA though? If it is undirected, the same (non-negative) edge will not be re-relaxed as if it is, the distance will increase, not decrease. Or are you talking about the negative cycle? If that's the case, then the idea of a shortest path is ill-defined. It's kinda like asking a longest path when there is a cycle.
"There is no input graph that can make Bellman Ford’s algorithm runs slower than O(V E). PS: The input graph has to be a simple graph without self-loop or multiple edges." Oh so you meant bad inputs. Well, we can always say the input is padded with M = 10^100 characters of rubbish each time to make it not O(VE), but I guess it's up to Halim to clarify
A few things (6 marks) For these six sub-questions, you are not allowed to use any additional data structure. What is the tightest time complexity of DFS if it is run from a source vertex v of a graph G, if:
This graph G is a tree and is stored in an Edge List: .
(4 marks) What is the best algorithm (write down the name and it’s default time complexity) to find the shortest paths from source s to the other vertices in the graph if the graph is:
undirected, weighted, and may have negative weight cycle:
Modified Djikstra's O(ELogV) Unweighted, BFS should do right?
??? Bellman should be needed. All edge just becomes double edge
The original Dijkstra’s algorithm (verbatim, as outlined in Lecture 09) can be used to detect the presence of negative weight cycle.
False. Greedy algorithm. Will go on forever. Technically, Dj should terminate, but give WA. Mod Dj is the one that goes forever
There is no input graph that can make Bellman Ford’s algorithm runs slower than O(V E). PS: The input graph has to be a simple graph without self-loop or multiple edges.
Confused by the Question. BF Killer considered O(VE)? BF killer runs the max total of O(VE) which is its worse case right? BF runs O(kE), where k is the number of loops it runs