title: How to determine if two nodes are part of a same tree/graph?
body: <p>I was asked this question in an interview to determine if two people are directly or indirectly connected on facebook.</p>
  
  <p>say a has a few friends b,c,d,e and c had few friends b,d,f,g and f has friends x,y,z. then a and z are indirect friends.</p>
  
  <p>Is there a good algorithm to found out how they are connected?</p>
  
  <p><a href="https://stackoverflow.com/questions/354330/how-to-determine-if-two-nodes-are-connected">This</a> post had similar question but he has too many criterias so i thought there must be a better way to do it. Can anyone just advice ?</p>