binary search and dfs