Improve the primary array selection using breadth-first search