title: Puzzle to identify shortest route
body: <p>Today I was going through a problem where we have to identify a shortest distance between a source and destination</p>
  
  <p>There are many nodes say each node is a airport in a city(PSB the image) and count is the number of flights between the cities .Now I have to identify the shortest route between two given cities </p>
  
  <p>Now the way I have thought of is I will take a hashMap which will store source city as key and destination city as value .</p>
  
  <p>Now to identify the shortest route between two given cities what I will do is search the keyset to identify the entry object which contain the source city and search the destination city in the values of the HM like</p>
  
  <p>My HM will be like (ref the image to understand the entries in the hm)</p>
  
  <pre><code>hm.put(h,b);
  hm.put(b,c);
  hm.put(c,e);
  hm.put(b,e);
  </code></pre>
  
  <p>Now suppose I have been asked to identify the shortest route between h and e </p>
  
  <p>As per my algorithm i will search the <strong>keyset</strong> of hm  for "h" city . </p>
  
  <p>1) I will get <code>&lt;h,b&gt;</code> map entry object
      Now I will traverse the hm <code>valueSet</code> for "e" city. 
     2) I will get <code>&lt;c,e&gt;</code> and <code>&lt;b,e&gt;</code> map entry object</p>
  
  <p>Now with the help of the entry.value which is <code>b</code> which I got from Step 1, i will try to associate the key from the entry object I got from Step 2 and thus i will identify that h-b-e is shorter distance compare to h-b-c-e </p>
  
  <p><img src="https://i.stack.imgur.com/pl0rb.png" alt="enter image description here"></p>
  
  <p>I not only wants to understand if there is any better solution to the problem but also i want to understand any book or link where I can get such kind of design problems.</p>