For every node in a n node tree except the root, there must be an edge pointing to the node's parent. There are $n-1$ such nodes, thus there must be $n-1$ edges.
start with node s. set n = 1 While node t is not found and there are connected nodes explore all nodes n steps away from s n++
BFS(G,s)
- For all v $\ni$ V
- v.status = UNKNOWN, v.depth = $\infty$
- EndFor
- s.status = discovered
- s.parent = null
- s.depth = 0
- Q.Enqueue(s)
- While Q.Size() > 0 do
- v = Q.Dequeue()
- v.status = done
- For each u adjacent to v
- If u.status = unknown
- u.status = discovered
- u.parent = v
- u.depth = v.depth+1
- Q.Enqueue(u)
- EndIF
- EndFor
- EndWhile