non recursive graph search