Read the following questions and solve them also provide an algorithm for each question…
- User
Read the following questions and solve them also provide an algorithm for each question in the following format : Format: ALGORITHM CoinRow(C[1..n]) //Applies formula (8.3) bottom up to find the maximum amount of money //that can be picked up from a coin row without picking two adjacent coins //Input: Array C[1..n] of positive integers indicating the coin values //Output: The maximum amount of money that can be picked up F[0]← 0; F[1]← C[1] for i ← 2 to n do F[i]← max(C[i] + F[i − 2], F[i − 1]) return F[n] questions:
- a. Continue the backtracking search for a solution to the four-queens problem, which was started in this section, to find the second solution to the problem. b. Explain how the board’s symmetry can be used to find the second solution to the four-queens problem.
- a. Which is the last solution to the five-queens problem found by the backtracking algorithm?
- Design a linear-time algorithm that finds a solution to the n-queens problem for any n ≥ 4.
- Generate all permutations of {1, 2, 3, 4} by backtracking and show each while calulation
- a. Apply backtracking to solve the following instance of the subset sum problem: A = {1, 3, 4, 5} and d = 11. b. Will the backtracking algorithm work correctly if we use just one of the two inequalities to terminate a node as nonpromising
- The general template for backtracking algorithms, which is given in the sec tion, ALGORITHM Backtrack(X[1..i]) //Gives a template of a generic backtracking algorithm //Input: X[1..i] specifies first i promising components of a solution //Output: All the tuples representing the problem’s solutions if X[1..i] is a solution write X[1..i] else //see Problem 9 in this section’s exercises for each element x ∈ Si+1 consistent with X[1..i] and the constraints do X[i + 1]← x Backtrack(X[1..i + 1]) works correctly only if no solution is a prefix to another solution to the problem. Change the template’s pseudocode to work correctly without this restriction. 11.Puzzle pegs This puzzle-like game is played on a board with 15 small holes arranged in an equilateral triangle. In an initial position, all but one of the holes are occupied by pegs, as in the example shown below. A legal move is a jump of a peg over its immediate neighbor into an empty square opposite; the jump removes the jumped-over neighbor from the board. Design and implement a backtracking algorithm for solving the following versions of this puzzle. a. Starting with a given location of the empty hole, find a shortest sequence of moves that eliminates 14 pegs with no limitations on the final position of the remaining peg. b. Starting with a given location of the empty hole, find a shortest sequence of moves that eliminates 14 pegs with the remaining peg at the empty hole of the initial board.
- Assistant