in Education by
As the title said, I'm trying to implement an algorithm that finds out the distances between all pairs of nodes in given graph. But there is more: (Things that might help you) The graph is unweighted. Meaning that all the edges can be considered as having weight of 1. |E| <= 4*|V| The graph is pretty big (at most ~144 depth) The graph is directed There might be cycles I'm writing my code in python (please if you reference algorithms, code would be nice too :)) I know about Johnson's algorithm, Floyd-Warshal, and Dijkstra for all pairs. But these algorithms are good when the graph has weights. I was wondering if there is a better algorithm for my case, because those algorithms are intended for weighted graphs. Thanks! JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
There is space for improvement because in unweighted graphs, you gain an additional attribute which does not hold for weighted graphs, namely: For any edge directly connecting A to C, you know for sure that there is no shorter path via a third node B. With this in mind, you should be able to simplify Dijkstra's Algorithm: As you may know, it works with three sets of nodes: Those of which the definitive shortest path is known, those of which a preliminary distance has been calculated and those which have not yet been explored. When following an edge e from A (1.) to C (3.), original Dijkstra would move node C from (3.) to (2.). Since the above attribute holds in all your graphs, you can however add it directly to the set (1.), which is more efficient. Here's the essential observation: The procedure outlined above is basically a BFS (breadth first search), i.e. you can find the distance from some fixed node v to any other node in O(|V| + |E|). You did not mention in your original question that the graph was basically a grid with some holes in it. This is an even stronger requirement, and I am sure you can exploit it. Doing a quick search for "grid graph shortest path" yields this paper which promises O(sqrt(n)) in the best case. As the problem you specify is fairly well-structured, I'm almost sure there are several more papers which you might want to look into.

Related questions

0 votes
    In a Neural Network, all the edges and nodes have the same Weight and Bias values. (a) True (b) False...
asked Oct 19, 2020 in Technology by Editorial Staff
0 votes
    If the weight matrix stores association between adjacent pairs of patterns, then network becomes? (a) ... temporal associative memory Please answer the above question....
asked Aug 27, 2022 in Education by JackTerrance
0 votes
    For ____________, the error is calculated by finding the sum of squared distance between actual and predicted values. (1) ... (2)None of the options (3)Clustering (4)Regression...
asked May 22, 2021 in Technology by JackTerrance
0 votes
    An electric field on a plane is described by its potential V = 20(r^-1 + r^-2), ... theory proposed by,electromagnetic theory engineering physics,electromagnetic theory nptel...
asked Nov 6, 2021 in Education by JackTerrance
0 votes
    Let a(l), b(l) represent in input-output pairs, where l varies in natural range of no.s, then if ... heteroassociation (d) none of the mentioned Please answer the above question....
asked Sep 3, 2022 in Education by JackTerrance
0 votes
    The result which operation contains all pairs of tuples from the two relations, regardless of whether their ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    The cpu scheduling algorithm best suited for time sharing os is Select the correct answer from above options...
asked Dec 21, 2021 in Education by JackTerrance
0 votes
    The algorithm that consumes minimum amount of ______ is to be considered as the best algorithm for a problem. Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    I have the following XML file that I'm trying to iterate through using xml.etree: SUCCESS 1234 12 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Which is a possible way of finding all the img elements in the document? (a) document(images) (b) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 22, 2021 in Education by JackTerrance
0 votes
    What statement BEST describes why the Big-O notation is a very useful way of analyzing algorithm complexity? ... analyzing algorithms Select the correct answer from above options...
asked Dec 22, 2021 in Education by JackTerrance
0 votes
    What is the Algorithm Update, What is the best source to know updates?...
asked Mar 5, 2021 in Technology by Editorial Staff
...