Question: Purpose: To understand and build a backtracking algorithm that checks for a path with strictly increasing letters inside a grid of lower - case letters,
Purpose: To understand and build a backtracking algorithm that checks for a path with strictly increasing letters inside a grid of lowercase letters, as detailed below.
You will implement the class WordSearchPuzzle, which implements the WordSearchInterface defined in WordSearchInterface.java. The interface has a single method, as specified below.
public interface WordSearchInterface
Check if a path exists on a word search puzzle grid with strictly increasing adjacent alphabet letters from a start cell to an end cell.
A Word Search Puzzle is an nbyn grid of lowercase English letters. Each cell in the grid can be represented by its row
number and column number. Row and column numbers are to n inclusive, where n is the grid size.
A cell is adjacent to another if it is next to it along any of
The class header is as follows.
public class WordSearchPuzzle implements WordSearchInterface
Find a path in the puzzle
A Word Search puzzle is a dimensional grid of lowercase English letters, such as the one below.
blnksreoomhs
eaocytsileot
stgarertrrgt
drltaswesgit
eoasnnogoebt
zsttiitnfser
inrjbioaholo
toquicksorts
risqueuertcl
otxdrchoeuel
mciaacuscrre
aelreprnnish
Each cell in the grid can be represented by its row and column numbers. Row and column numbers are in the range to n inclusive, where n is the grid size, in the given example. For example, the upleft cell of the grid can be represented as because it is on the first row and the first column. The downright cell is
Your goal in this assignment is to check if we can move from one cell to another using adjacent letters without violating the alphabetic order of letters. For example, it is possible to move from to using adjacent cells and without violating the order of the alphabet as follows.
Start at b at
Blnksreoomhs
eaocytsileot
stgarertrrgt
drltaswesgit
eoasnnogoebt
zsttiitnfser
inrjbioaholo
toquicksorts
risqueuertcl
otxdrchoeuel
mciaacuscrre
aelreprnnish
Move to l at
BLnksreoomhs
eaocytsileot
stgarertrrgt
drltaswesgit
eoasnnogoebt
zsttiitnfser
inrjbioaholo
toquicksorts
risqueuertcl
otxdrchoeuel
mciaacuscrre
aelreprnnish
Move to n at
BLNksreoomhs
eaocytsileot
stgarertrrgt
drltaswesgit
eoasnnogoebt
zsttiitnfser
inrjbioaholo
toquicksorts
risqueuertcl
otxdrchoeuel
mciaacuscrre
aelreprnnish
Move to o at
BLNksreoomhs
eaOcytsileot
stgarertrrgt
drltaswesgit
eoasnnogoebt
zsttiitnfser
inrjbioaholo
toquicksorts
risqueuertcl
otxdrchoeuel
mciaacuscrre
aelreprnnish
Move to t at
BLNksreoomhs
eaOcytsileot
sTgarertrrgt
drltaswesgit
eoasnnogoebt
zsttiitnfser
inrjbioaholo
toquicksorts
risqueuertcl
otxdrchoeuel
mciaacuscrre
aelreprnnish
The sequence of the letters we visited on that path is blnot which represents a strictly increasing sequence of letters; that is it doesn't violate the order of the alphabet.
BLNksreoomhs
eaOcytsileot
sTgarertrrgt
drltaswesgit
eoasnnogoebt
zsttiitnfser
inrjbioaholo
toquicksorts
risqueuertcl
otxdrchoeuel
mciaacuscrre
aelreprnnish
Note that the letters on the path are shown in uppercase for illustration only. Your code shouldn't change the grid. Also, note that each pair of consecutive letters is adjacent along one of the eight directions. The eight directions in clockwise order are right, downright, down, downleft, left, upleft, up and upright.
You must implement this search using backtracking.
Hint: define a private recursive helper method to perform backtracking and call it from your implementation of the isIncreasingSequencePossible method. An example helper method is:
private boolean solvechar grid, int currentRow, int currentCol, int endRow, int endCol
Please check the backtracking framework in the lecture notes and its explanation in the lecture videos.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
