Dfs Algorithm Python Binary Search Code