-4

In input we have length and width of maze, and the maze that looks like

A..#
##.#
#B.#
####

Where "#" - is wall, A- start point, B - end point. In output we should to see a length of shortest route in maze. I was reading a lot of examples of codes, but i'm not understanding it, because in java I saw one example only, and it has Queue, I'm started learning java not a long time ago and I'm don't know about it. Can you show me example without Queue? Thanks a lot :)

If BFS can't working without Queque, can you show me example of DFS algorithm?

rustock
  • 387
  • 3
  • 6
  • 12
  • I'm not really sure how you'd do a BFS *without* a queue, or some sort of linear ordering of nodes, to be honest... – Makoto Apr 19 '13 at 18:15
  • Breadth-first search uses a queue. That's pretty fundamental. Would you be interested in a depth-first search algorithm, which does not? – John Kugelman Apr 19 '13 at 18:15
  • 1
    I think it might be easier if you simply read and understood the Queue API, which is fairly simple: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Queue.html – tbkn23 Apr 19 '13 at 18:15
  • For what it's worth, if you don't understand queues and stacks you should learn those concepts before you try to tackle search algorithms. – John Kugelman Apr 19 '13 at 18:17
  • If BFS can't working without Queque, can you show me example of DFS algorithm? – rustock Apr 19 '13 at 18:20

1 Answers1

2

If you are planning to find the shortest path, you better use BFS instead of DFS.

It is not really about Java or C or other language that you are using. It's the concepts. But before any coding, @John said, you better have a look around Queues, minimum Queues, stacks, Lists and such stuff (simply, "Data Structures"). Those are the main concepts of programming.

If you are interested, have a look at Dijkstra's Algorithm or Bellman FordAlgorithm to learn about the well known shortest path algorithms.

Praneeth Peiris
  • 2,008
  • 20
  • 40