How can I improve this algorithm from $$$\mathcal{O}(V^4)$$$ to $$$\mathcal{O}(V^2)$$$?

Revision en1, by bigintegers, 2019-12-13 22:48:29

This is a problem on an algorithms final that I'm studying for.

You are tryng to get from City A to City for the cheapest cost. Your company will pay for exactly one flight between two cities (from a list of flights), but aside from that, you need to drive from the rest of the trip. Given a matrix $$$C[x, y]$$$ that represents the money needed to drive from city $$$x$$$ to city $$$y$$$, and a Boolean matrix $$$F[x, y]$$$, which is TRUE if there's a flight from $$$x$$$ to $$$y$$$ and FALSE otherwise, find an algorithm that finds the minimum amount of money you have to pay to get form $$$A$$$ to $$$B$$$.

This is a problem from a previous final that I am studying with. Apparently the full credit solution was something that runs in $$$\mathcal{O}(V^2)$$$ time, but the only solution that I can think of is to run Dijkstra's $$$n^2$$$ times (bruteforce). Can someone please help me study? We haven't covered anything super advanced (this is an intro algorithms class).

Tags #algorithms, #graph, all-shortest-path, #dijkstra, #graph theory

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English bigintegers 2019-12-13 22:48:29 1022 Initial revision (published)