SlideShare a Scribd company logo
1 of 20
“MAZE” Problem
& its Solution
By-Mudit Dholakia(14MTPOS001-MT005)
Guide:-Prof.P.M.Jadav
What is ‘maze’?
• Maze means confusing in nature.
• A network of paths and hedges designed as a puzzle through which
one has to find a way.
• DAZED
What to do with computers?
• It is easy to understand for a matured person.
• But what if we solve it using computer.????
?
Instruct Computer
• Solution is to devise an algorithm for given maze.
DYNAMIC
EFFECTIVE
Available Approaches
• Dynamic Programming
• Backtracking
• Greedy Approach
Backtracking?!
• We will solve this problem using backtracking.
• The reason behind this is we have pre-defined constraints.
• Hence it facilitates some ease for the programmer to choose the best
solutions.
• It also avoids undesired computations.
Example
Expected Solution
• 11x22 matrix
• “0”->wall
• “1”->gap
• Source Position (8,15)
• Destination Position(10,18)
Thinking from programmer’s perspective
• Constraints are there
• Array (matrix) is there
• Exploration of the right path is to be done
• “IN GENERAL WE HAVE TO FIND A CLEAR PATH TOWARDS
DESTINATION”
• 1. Consider the VISITED node, if it is ‘eligible’ for exploration.
• 2.Move forward else ‘stop’.
Ideal Algorithm
• 1. Consider a diamond neighbourhood of the algorithm.(i.e.
immediate neighbours HORIZONTALY and VERTICALY)
• 2.If ‘eligible’ move ahead having a track of backward knowledge
• 3.Else if not end then find another neighbour and follow step 2.
• 4.else ‘stop’
Tree consideration
• If we consider this problem solution to be an application of the
traditional tree then it is clear that “DFS-Depth First Search” tree
algorithm can solve this.
• Because in DFS we maintain all the visited track globally and move
further. So that visit consistency and order can be preserved.
Check for safe position
• int isSafe(int x,int y,int G[V1][V2],int Sol[V1][V2]) /* to check the safe move */
• {
• if(x>=0 && x<V1 && y>=0&&y<V2 && G[x][y]==1 && !Sol[x][y])
• {
• return 1;
• }
• else
• {
• return 0;
• }
• }
int MazeRecur(int G[V1][V2], int Sol[V1][V2], int x,int y) /* checking for the path to our exit point */
{
if(x==er &&y==ec)
{
Sol[x][y]=1;
return 1;
}
if(isSafe(x,y,G,Sol)==1)
{
printf("->(%d,%d)->",x,y);
Sol[x][y]=1;
if(MazeRecur(G,Sol,x,y-1)==1) /* left move possible */
{
return 1;
}
if(MazeRecur(G,Sol,x,y+1)==1) /* right move possible */
{
return 1;
}
if(MazeRecur(G,Sol,x-1,y)==1) /* up move possible */
{
return 1;
}
if(MazeRecur(G,Sol,x+1,y)==1) /* down move possible */
{
return 1;
}
Sol[x][y]=0;
}
return 0;
}
Immediate Neighbours
Implementing through C language
Time Complexity
• Consider only depth first search
of nodes.
• For mxn matrix to iterate the
search of node it will take
T(n*m/2) in worst case.
• And we add DFS recursive
backtrack algorithm time
T(n)=4T(n-1) for the 4 immediate
neighbours.
• T(n)=4T(nxm)
• Using master’s theorem it will
take 4 𝑛∗𝑚 exponential time.
• If we use backtracking then it
can be reduced to 2 𝑛∗𝑚
.
Improved algorithm can be designed …
• Using stack
• Using some enumerated datatypes
• Using K-connected neighbourhood concept
• Indexed data structures
References
• http://www.geeksforgeeks.org/backttracking-set-2-rat-in-a-maze/
• http://en.wikipedia.org/wiki/Maze_solving_algorithm
• https://www.cs.bu.edu/teaching/alg/maze/
• http://techlanguageworld.blogspot.in/2014/02/c-program-to-solve-
maze-problem.html
Queries?
THANK YOU

More Related Content

Similar to DAA

"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)Tech in Asia ID
 
Machine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConfMachine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConfSeth Juarez
 
Lucio marcenaro tue summer_school
Lucio marcenaro tue summer_schoolLucio marcenaro tue summer_school
Lucio marcenaro tue summer_schoolJun Hu
 
(CMP305) Deep Learning on AWS Made EasyCmp305
(CMP305) Deep Learning on AWS Made EasyCmp305(CMP305) Deep Learning on AWS Made EasyCmp305
(CMP305) Deep Learning on AWS Made EasyCmp305Amazon Web Services
 
mini project_shortest path visualizer.pptx
mini project_shortest path visualizer.pptxmini project_shortest path visualizer.pptx
mini project_shortest path visualizer.pptxtusharpawar803067
 
EnrichmentWeek Binus Computer Vision
EnrichmentWeek Binus Computer VisionEnrichmentWeek Binus Computer Vision
EnrichmentWeek Binus Computer Visiongiamuhammad
 
LECTURE 7 REVIEW, EXCEPTIONS, IO.pdf
LECTURE 7 REVIEW, EXCEPTIONS, IO.pdfLECTURE 7 REVIEW, EXCEPTIONS, IO.pdf
LECTURE 7 REVIEW, EXCEPTIONS, IO.pdfShashikantSathe3
 
Appsec usa2013 js_libinsecurity_stefanodipaola
Appsec usa2013 js_libinsecurity_stefanodipaolaAppsec usa2013 js_libinsecurity_stefanodipaola
Appsec usa2013 js_libinsecurity_stefanodipaoladrewz lin
 
Introduction to Steering behaviours for Autonomous Agents
Introduction to Steering behaviours for Autonomous AgentsIntroduction to Steering behaviours for Autonomous Agents
Introduction to Steering behaviours for Autonomous AgentsBryan Duggan
 
Understanding Basics of Machine Learning
Understanding Basics of Machine LearningUnderstanding Basics of Machine Learning
Understanding Basics of Machine LearningPranav Ainavolu
 
Automated Design Validation The Solid Works Api
Automated Design Validation The Solid Works ApiAutomated Design Validation The Solid Works Api
Automated Design Validation The Solid Works ApiRazorleaf Corporation
 
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptxPPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptxRaviKiranVarma4
 
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Fwdays
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software DevelopmentNaveenkumar Muguda
 
Embedded SW Interview Questions
Embedded SW Interview Questions Embedded SW Interview Questions
Embedded SW Interview Questions PiTechnologies
 

Similar to DAA (20)

"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
 
chapter3part1.ppt
chapter3part1.pptchapter3part1.ppt
chapter3part1.ppt
 
Machine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConfMachine Learning on Azure - AzureConf
Machine Learning on Azure - AzureConf
 
Lucio marcenaro tue summer_school
Lucio marcenaro tue summer_schoolLucio marcenaro tue summer_school
Lucio marcenaro tue summer_school
 
(CMP305) Deep Learning on AWS Made EasyCmp305
(CMP305) Deep Learning on AWS Made EasyCmp305(CMP305) Deep Learning on AWS Made EasyCmp305
(CMP305) Deep Learning on AWS Made EasyCmp305
 
mini project_shortest path visualizer.pptx
mini project_shortest path visualizer.pptxmini project_shortest path visualizer.pptx
mini project_shortest path visualizer.pptx
 
EnrichmentWeek Binus Computer Vision
EnrichmentWeek Binus Computer VisionEnrichmentWeek Binus Computer Vision
EnrichmentWeek Binus Computer Vision
 
LECTURE 7 REVIEW, EXCEPTIONS, IO.pdf
LECTURE 7 REVIEW, EXCEPTIONS, IO.pdfLECTURE 7 REVIEW, EXCEPTIONS, IO.pdf
LECTURE 7 REVIEW, EXCEPTIONS, IO.pdf
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
Appsec usa2013 js_libinsecurity_stefanodipaola
Appsec usa2013 js_libinsecurity_stefanodipaolaAppsec usa2013 js_libinsecurity_stefanodipaola
Appsec usa2013 js_libinsecurity_stefanodipaola
 
RSA ALGORITHM
RSA ALGORITHMRSA ALGORITHM
RSA ALGORITHM
 
Tutorial matlab
Tutorial matlabTutorial matlab
Tutorial matlab
 
Tutorialmatlab kurniawan.s
Tutorialmatlab kurniawan.sTutorialmatlab kurniawan.s
Tutorialmatlab kurniawan.s
 
Introduction to Steering behaviours for Autonomous Agents
Introduction to Steering behaviours for Autonomous AgentsIntroduction to Steering behaviours for Autonomous Agents
Introduction to Steering behaviours for Autonomous Agents
 
Understanding Basics of Machine Learning
Understanding Basics of Machine LearningUnderstanding Basics of Machine Learning
Understanding Basics of Machine Learning
 
Automated Design Validation The Solid Works Api
Automated Design Validation The Solid Works ApiAutomated Design Validation The Solid Works Api
Automated Design Validation The Solid Works Api
 
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptxPPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
PPT ON INTRODUCTION TO AI- UNIT-1-PART-2.pptx
 
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software Development
 
Embedded SW Interview Questions
Embedded SW Interview Questions Embedded SW Interview Questions
Embedded SW Interview Questions
 

DAA

  • 1. “MAZE” Problem & its Solution By-Mudit Dholakia(14MTPOS001-MT005) Guide:-Prof.P.M.Jadav
  • 2. What is ‘maze’? • Maze means confusing in nature. • A network of paths and hedges designed as a puzzle through which one has to find a way. • DAZED
  • 3. What to do with computers? • It is easy to understand for a matured person. • But what if we solve it using computer.???? ?
  • 4. Instruct Computer • Solution is to devise an algorithm for given maze. DYNAMIC EFFECTIVE
  • 5. Available Approaches • Dynamic Programming • Backtracking • Greedy Approach
  • 6. Backtracking?! • We will solve this problem using backtracking. • The reason behind this is we have pre-defined constraints. • Hence it facilitates some ease for the programmer to choose the best solutions. • It also avoids undesired computations.
  • 8. Expected Solution • 11x22 matrix • “0”->wall • “1”->gap • Source Position (8,15) • Destination Position(10,18)
  • 9. Thinking from programmer’s perspective • Constraints are there • Array (matrix) is there • Exploration of the right path is to be done • “IN GENERAL WE HAVE TO FIND A CLEAR PATH TOWARDS DESTINATION” • 1. Consider the VISITED node, if it is ‘eligible’ for exploration. • 2.Move forward else ‘stop’.
  • 10. Ideal Algorithm • 1. Consider a diamond neighbourhood of the algorithm.(i.e. immediate neighbours HORIZONTALY and VERTICALY) • 2.If ‘eligible’ move ahead having a track of backward knowledge • 3.Else if not end then find another neighbour and follow step 2. • 4.else ‘stop’
  • 11. Tree consideration • If we consider this problem solution to be an application of the traditional tree then it is clear that “DFS-Depth First Search” tree algorithm can solve this. • Because in DFS we maintain all the visited track globally and move further. So that visit consistency and order can be preserved.
  • 12. Check for safe position • int isSafe(int x,int y,int G[V1][V2],int Sol[V1][V2]) /* to check the safe move */ • { • if(x>=0 && x<V1 && y>=0&&y<V2 && G[x][y]==1 && !Sol[x][y]) • { • return 1; • } • else • { • return 0; • } • }
  • 13. int MazeRecur(int G[V1][V2], int Sol[V1][V2], int x,int y) /* checking for the path to our exit point */ { if(x==er &&y==ec) { Sol[x][y]=1; return 1; } if(isSafe(x,y,G,Sol)==1) { printf("->(%d,%d)->",x,y); Sol[x][y]=1; if(MazeRecur(G,Sol,x,y-1)==1) /* left move possible */ { return 1; } if(MazeRecur(G,Sol,x,y+1)==1) /* right move possible */ { return 1; } if(MazeRecur(G,Sol,x-1,y)==1) /* up move possible */ { return 1; } if(MazeRecur(G,Sol,x+1,y)==1) /* down move possible */ { return 1; } Sol[x][y]=0; } return 0; }
  • 16. Time Complexity • Consider only depth first search of nodes. • For mxn matrix to iterate the search of node it will take T(n*m/2) in worst case. • And we add DFS recursive backtrack algorithm time T(n)=4T(n-1) for the 4 immediate neighbours. • T(n)=4T(nxm) • Using master’s theorem it will take 4 𝑛∗𝑚 exponential time. • If we use backtracking then it can be reduced to 2 𝑛∗𝑚 .
  • 17. Improved algorithm can be designed … • Using stack • Using some enumerated datatypes • Using K-connected neighbourhood concept • Indexed data structures
  • 18. References • http://www.geeksforgeeks.org/backttracking-set-2-rat-in-a-maze/ • http://en.wikipedia.org/wiki/Maze_solving_algorithm • https://www.cs.bu.edu/teaching/alg/maze/ • http://techlanguageworld.blogspot.in/2014/02/c-program-to-solve- maze-problem.html