📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store
  • ✖

      Question

      Consider a simplified backtracking approach for

      generating permutations of [1, 2, 3]. If the current partial permutation is [1, 3], what is the next logical step in the backtracking process?
      A Add 2 to get [1, 3, 2]. Correct Answer Incorrect Answer
      B Backtrack, remove 3, and try to place 2 after 1 to get [1, 2]. Correct Answer Incorrect Answer
      C Terminate as [1, 3] is not a full permutation. Correct Answer Incorrect Answer
      D Start over from an empty permutation. Correct Answer Incorrect Answer
      E Add 1 again to get [1, 3, 1]. Correct Answer Incorrect Answer

      Solution

      If the current partial permutation is [1, 3], and we are trying to build a permutation of [1, 2, 3], the remaining available element is 2. The next logical step is to try adding 2 to the current partial permutation, forming [1, 3, 2]. If this forms a complete and valid permutation, it's a solution. If not, then we would backtrack from [1, 3, 2] to [1, 3], and since there are no other choices for the third position, we would then backtrack further to [1].

      Practice Next
      ask-question