Skip to content

Find the occurrence of a word in a given matrix using backtracking for humans ๐Ÿ”Ž

License

Notifications You must be signed in to change notification settings

akshaybahadur21/StringRecognitionUsingBacktracking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Find word occurance in a matrix using backtracking ๐Ÿ”Ž

This code helps you to understand the occurance of a word in a given matrix using backtracking.

Code Requirements ๐Ÿฆ„

The example code is in Java (version 1.8 or higher will work).

Description ๐Ÿ”ญ

Backtracking is a general algorithm for finding all (or some) solutions to some computational problems, notably constraint satisfaction problems, that incrementally builds candidates to the solutions, and abandons each partial candidate ("backtracks") as soon as it determines that the candidate cannot possibly be completed to a valid solution.

Given a 2D matrix of charยญacยญters. Check whether the word exist in the matrix or not. If it exists then print its path. All moveยญments are allowed (right, left, up, down and diagonally).

For more information, see

Results ๐Ÿ“Š

                 if(solveMaze(a,sol,x+1,y,str,n,l,count)==1)
				 return 1;
			 if(solveMaze(a,sol,x,y+1,str,n,l,count)==1)
				 return 1;
			  if(solveMaze(a,sol,x-1,y,str,n,l,count)==1)
				 return 1;
			  if(solveMaze(a,sol,x,y-1,str,n,l,count)==1)
				 return 1;
			 sol[x][y]='\0';//backtracking
			 return -1;
			 

Execution ๐Ÿ‰

To compile the code, simply run the javac BackTrack.java. To run the code, type java BackTrack

javac BackTrack.java
java BackTrack

Releases

No releases published

Packages

No packages published

Languages