954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Graph And Data Structure

Hey , i am new to data structure and specially Graph .
And i was going through a problem for finding the best path http://www.codechef.com/JULY11/problems/LOKBIL/ And couldn't think something usable.

SO , if u guys help that will be a good start of me on this site too.

PS i know contest is live so all i want is how to start , and little hint for program .

Thanks in Advance !!

melfoy
Newbie Poster
2 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 
\007
Junior Poster in Training
67 posts since Apr 2011
Reputation Points: 21
Solved Threads: 6
 
Dijkstra is your man.


Thank u for ur advice but it would be better if u elaborate little better as i went through Dijkstra' Algo and got that it is for weighted graph for least weight path rather than least number of path .

And i made an algo myself by using n*n matrix having complexity O(n^4) and got TLE(time limit exceed).

if u help a more that 'll be kind :)

melfoy
Newbie Poster
2 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 
Thank u for ur advice but it would be better if u elaborate little better as i went through Dijkstra' Algo and got that it is for weighted graph for least weight path rather than least number of path .


Dijkstra is a least number path problem, it will give you shortest path for a single source,
But after reading your prblem, so far I understand you need all pair shortest path, which will give you the shortest paths from every source to every destination in O(n^3)

After finding the shortest path, you need to find the average of those path per source, which is another O(n^2) search, then just need to give output of the lowest average one.

Complexity = O(n^3) + O(n^2)
you can ommit O(n^2)
so basically its O(n^3)

Here is the all pair shortest path algo: all pair shortest path

Your input should create a graph where each existing edge's weight will be 1, and non existing edge will be infinity (MAX_INT)

Best of luck.

alwaysLearning0
Junior Poster
119 posts since Apr 2009
Reputation Points: 64
Solved Threads: 19
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: