Answer to Question #162038 in C++ for anita

Question #162038

Your friend is developing a maze puzzle game and already designed a module which can generate a random maze. The maze has one entry and one exit point. Now he needs to develop the module which will find the path from entry to exit points for randomly generated maze. Your friend wants the path searching should be quickest. He can use only Stack or Queue data structures to store maze’s visited locations for path generation. He is unable to decide the selection of data structure and asked you to help him.

GDB Question: 

From Stack and Queue data structures which data structure you will suggest using for entry to exit path finding module? Select a data structure and give comments in favour to justify your selection. Also mention why you are not selecting the other data structure?


1
Expert's answer
2021-02-08T08:54:29-0500

I would suggest Stack data structure over Queue. This is because in solving a maze problem, we need to explore all possible paths. Along with that, we also need to track the paths visited.

If we were to use Queue, then after finding an unsuccessful path, we'll have to start again from the entry point as the queue only supports deletion from the front (FIFO property). This would not be useful in our case, as we need to trace back the unsuccessful path until we find another way.

Using Stack, what we can do is, while moving into the maze, we can push the index of the last visited cell and when reached the end of the maze(not exit-point), just keep popping elements from the stack until the cell at stack Top has another way to move.

Using this approach (particularly stack), you can find the correct path in the shortest possible time. 


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment