Is it possible to form a table that will have simply the shortest distance from each source to destination using q learning?
If not, suggest any other learning algorithm.
Welcome to AI.SE Adarsh!
This is fairly simple to do with Q-Learning.
If you assign a reward equal to -1 for each location other than the goals, and 0 for the goals, then Q-learning with no discount factor will learn the length of the shortest path from each location to the goal. Alternatively, you can use a discounting factor, and then invert the equation on the learned values of the Q function to obtain the number of steps.
Hope this helps!