search rooms algorithm