title: Determine whether there is a path from vertex u to w passing through v
body: <p>Given an undirected graph <code>G = (V, E)</code>, such that <code>u</code>, <code>v</code>, <code>w</code> are some edges in G.</p>
  <p>Describe an algorithm to determine whether</p>
  <p><em>&quot;if there is a path from u to w that passes through v&quot;</em></p>
  <p>A simple algorithm for that using DFS is given below:</p>
  <pre><code>bool checkFunction(){
  
    graph g; // containing u, w, v
    dfs(v);
  
    if(isVisited(u) &amp;&amp; isVisited(w))
      return true;
    else
      return false;
     
  }
  </code></pre>
  <p>For the above algorithm,</p>
  <ul>
  <li>time complexity    :    O(V+E)</li>
  <li>space complexity   :    O(V)</li>
  </ul>
  <p>But can we reduce the time complexity?</p>