Breadth first search and depth first search