We saw during our discussion of the implementation of Graphs that there are two broad implementation strategies that we can choose if we're implementing a graph: adjacency lists or an adjacency matrix. The difference turns out not to be academic, nor is it a matter of convenience or familiarity; the distinction is a critical one that we need to get right.
For each of the scenarios described below, choose one of the implementation strategies or the other — either adjacency lists or an adjacency matrix — and briefly explain, in a sentence or two, why your choice is the right one.
PLEASE UPVOTE THE SOLUTION
1. Adjacency Matrix: It is fast to lookup and
check for presence or absence of a specific edge
between any two nodes O(1)
2.Adjacency Lists: It is fast to iterate over all edges because you can access any node neighbors directly
3.Adjacency Lists: Recall that adjacency matrix
is a N by N array, either filled with true/false (if unweighted),
or the weight of the edge. This requires O(N^2) space complexity.
This is rather inefficient when the graph is sparse, meaning that
there is a lot less edges than N^2 nodes. Hence it shouldn't be
used.
We saw during our discussion of the implementation of Graphs that there are two broad implementation...
In this question, we will think about how to answer shortest path problems where we have more than just a single source and destination. Answer each of the following in English (not code or pseudocode). Each subpart requires at most a few sentences to answer. Answers significantly longer than required will not receive full credit You are in charge of routing ambulances to emergency calls. You have k ambulances in your fleet that are parked at different locations, and you...
Case 34 Emirates Airline Emirates Airline was one of the three Middle East carriers that were singled out by the largest US airlines in the report that was released on March 5, 2015. The report charged that that the flagship airline of Dubai, along with Etihad Airways and Qatar Airways, had received over $42 billion in government subsidies and tax breaks since 2004. Claiming that this gave an unfair advantage to these state-owned airlines, the US airlines demanded that the...