Question

In: Computer Science

Algorithm questions. 1.When choosing an algorithm for the shortest path between two nodes in an unweighted...

Algorithm questions.

1.When choosing an algorithm for the shortest path between two nodes in an unweighted graph, should we use Breadth First Search or Depth First Search ?

2. When choosing a data structure to store a graph for an algorithm, how should we store the graph knowing that the graph is dense and this algorithm needs to determine many times if two nodes are directly connected ? Should it be an Adjacency Matrix or an Adjacency List ?

Solutions

Expert Solution

Answer 1) Which algo for finding shortest path:
DFS Vs BFS

Both the graph traversals promises a complete traversal of the graph, visiting every vertex of the graph.
DFS uses the STACK Data structure for traversal whereas BFS uses the Queue Data structure. BFS uses more momory depending on the branching factor though BFS is a complete and optimal to find the shortest path between any two vertices in lowest depth possible.
In case of DFS, it is space efficient but it may find the a sub-optimal solution to find the path between two vertices, it stops at sub-optimal solution before finding the optimal solution.

Answer 2)

Data structure for Dense graph (Complete Graph):
A Graph G(V, E) can be undirected or directed graph, in case of adjacency matrics it consumes more space O(V^2)
the density of graph dont affect the space required to store the graph. With this in O(1) time we can find whether there is any connectivity between two vertices, removing of an edge can be done on O(1) time. Adding a vertex is O(V^2) time. So for Dense graph adjacency matrics is a good data structure.

In Case of Ajacency list it saves space O(|V|+|E|) . But here the graph is dense so number of edges will be more(n(n − 1)/2) so it is not efficient In the worst case. To find the edge between two vertex can be done in O(V)


Related Solutions

In the shortest-path algorithm we are concerned with the total length of the path between a...
In the shortest-path algorithm we are concerned with the total length of the path between a source and every other node. Suppose instead that we are concerned with the length of the longest edge between the source and every node. That is, the bottleneck of a path is defined to be the length of the longest edge in the path. Design an efficient algorithm to solve the single source smallest bottleneck problem; i.e. find the paths from a source to...
You will implement two algorithms to find the shortest path in a graph. def prim(G,start_node): Takes...
You will implement two algorithms to find the shortest path in a graph. def prim(G,start_node): Takes a graph G and node to start at. Prims edges used in MST. def kruskal(G): Takes a graph G and prints the edges in the MST in order found. You may represent the graphs as adjacency matrix or list. You MAY NOT include any graph libraries. The graph you are working on will be give in a file with the following format. The graph...
Bellman-Ford and Dijkstra's algorithms solve the single-source shortest path (SSSP) problem. Explain the circumstances when you...
Bellman-Ford and Dijkstra's algorithms solve the single-source shortest path (SSSP) problem. Explain the circumstances when you would use each of these algorithms.   
Write a program that implements the A* algorithm to find a path from any two given...
Write a program that implements the A* algorithm to find a path from any two given nodes. You may use any of the following languages: C++, C#, Java, ActionScript. Problem Overview & Algorithm Description In a fully-observable environment where there are both pathable and blocked nodes, an agent must find a good path from their starting node to the goal node. The agent must use the A* algorithm to determine its path. For this program, you must use the Manhattan...
Describe how the Shortest Job First (SJF)Scheduling algorithm works. Explain the differences of working procedure between...
Describe how the Shortest Job First (SJF)Scheduling algorithm works. Explain the differences of working procedure between preemptive and non-preemptive version of this algorithm.
1. When choosing a business form, what are they key difference between proprietorship, partnership and a...
1. When choosing a business form, what are they key difference between proprietorship, partnership and a corporation? 2. What are the seven (7) characteristics of a partnership? 3. What are the differences between a/an a. Limited liability Partnership b. Limited liability Corporation c. S Corporation? 4. What factors are taken into consideration when choosing a business form? 5. What are the three (3) methods used to allocate income or loss? Explain each method. 6. What accounts are affected when recording...
When choosing between two alternative regression models for the same data, what criteria should be used...
When choosing between two alternative regression models for the same data, what criteria should be used to select the best model?
The airline carriers schedule the flights between pairs of cities through the shortest routes. Two airline...
The airline carriers schedule the flights between pairs of cities through the shortest routes. Two airline carriers are called equivalent if they offer the flights between the same pairs of cities. Design an algorithm with less than cubic time complexity to compare whether two given airline carriers are equivalent or not. Direct and connecting flights are not differentiated here.
You are choosing between two projects. The cash flows for the projects are given in the...
You are choosing between two projects. The cash flows for the projects are given in the following table​ ($ million): Project Year 0 Year 1 Year 2 Year 3 Year 4 A −$52 $27 $19 $22 $17 B −$100 $22 $41 $48 $61 a. What are the IRRs of the two​ projects? b. If your discount rate is 5.4%​, what are the NPVs of the two​ projects? c. Why do IRR and NPV rank the two projects​ differently?
You are choosing between two projects. The cash flows for the projects are given in the...
You are choosing between two projects. The cash flows for the projects are given in the following table​ ($ million): Project Year 0 Year 1 Year 2 Year 3 Year 4 A −$52 $27 $19 $18 $17 B −$101 $19 $40 $51 $58 a. What are the IRRs of the two​ projects? b. If your discount rate is 5.4%​, what are the NPVs of the two​ projects? c. Why do IRR and NPV rank the two projects​ differently? a. What...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT