title: Why is the time complexity of both DFS and BFS O( V + E )
body: <p>The basic algorithm for BFS:</p>
  
  <pre><code>set start vertex to visited
  
  load it into queue
  
  while queue not empty
  
     for each edge incident to vertex
  
          if its not visited
  
              load into queue
  
              mark vertex
  </code></pre>
  
  <p>So I would think the time complexity would be:  </p>
  
  <pre><code>v1 + (incident edges) + v2 + (incident edges) + .... + vn + (incident edges) 
  </code></pre>
  
  <p>where <code>v</code> is vertex <code>1</code> to <code>n</code></p>
  
  <p>Firstly, is what I've said correct?  Secondly, how is this <code>O(N + E)</code>, and intuition as to why would be really nice.  Thanks</p>