QuestionQuestion

In this assignment, you will be implementing backtracking search using recursion.You are given a starter file AtoY.java

You are given a five-by-five array of cells, some of which contain letters and the others are empty. You need to fill the empty squares with letters so that there is a path moving only horizontally or vertically (not diagonally) at each step that visits all cells with consecutive letters. The letters are lower case ‘a’ through ‘y’, and ‘a’ is present in one of the starting cells.For example, a solution to is Another way to describe the correct output is that if you place the cursor over the‘a’, then using only the up,down,left,and right arrows you can move the cursor over the letters ‘a’ through ‘y’ in order. Complete the recursive backtracking search function given in the Java file. The input to the program consists of five lines, each containing a string of five lower case letters from ‘a’ to ‘z’ with no spaces. An ‘a’ appears exactly once in the five lines. A ‘z’ indicates an empty cell. The output is five lines, each containing five characters (without spaces), and the five lines together contain each of the letters ‘a’ through ‘y’ according to the rules given above.For example, if the input is:

zzzzm
zzzzz
zfzzz
zzzaz
zzzzu

then a correct output is
ijklm
hgpon
efqrs
dcbat
yxwvu

If no solution exists, your program should produce no output. If more than one solution exists, print out just one.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

//package edu.njit.;

import java.util.Arrays;
import java.util.Scanner;

public class AtoY {

    public static void printTable(char[][] t) {
       for (int i = 0; i < 5; ++i) {
            for (int j = 0; j < 5; ++j)
                System.out.print(t[i][j]);
            System.out.println();
       }
    }

    // occupied[c] = true if character c is already on the table...
    static boolean[] occupied = new boolean[255];

    private static boolean solve(char[][] t, int row, int col, char c) {
       // table is completely filled, return true
       if (c == 'z')
            return true;...

By purchasing this solution you'll be able to access the following files:
AtoY.java.

$10.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats