Perfroming breadth first search on graphs