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...
Write a heuristic computer program to solve the shortest path routing problem using the Floyd-Warshall algorithm...
Write a heuristic computer program to solve the shortest path routing problem using the Floyd-Warshall algorithm discussed in the chapter using C++. The user should be able to input the node positions and link costs.
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...
(Computer Network Question)Answer the following questions when the two nodes with a point-to-point connection are communicating...
(Computer Network Question)Answer the following questions when the two nodes with a point-to-point connection are communicating with a link with a bandwidth of 8 Mbps and a one-way radio delay of 2 mssec. (The header overhead, i.e. header length, is ignored in the performance calculation process.) a)Draw a sliding window of 1KB (8000bit) frames with a size of 1KB (KB) when sending in a sliding window with a size of 2 transmission window, the process of operation if no error...
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?
ALGORITHM ANALYSIS AND DESIGN Analyze the given questions and answer accordingly 1.       Given the algorithm to...
ALGORITHM ANALYSIS AND DESIGN Analyze the given questions and answer accordingly 1.       Given the algorithm to calculate the factorial of ā€˜nā€™. Mathematically analyze the given recursive algorithm to find out the time complexity of the algorithm.    Algorithm F(n) If n = 0 return 1 Else Return f(n-1) * n
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT