It is necessary to bypass all the vertices of the graph in any order. What is better to use: search in width or in depth? What are the advantages and disadvantages of algorithms in principle?

  • @Unick and what's better? - user247920
  • one
    @ user247920 well, it depends on the task you want to solve. - Flowneee
  • @Flowneee didn't I write my task? - user247920
  • @ user247920 is a very common task. In this form, you can completely write a chapter of any textbook on algorithms. What shape is the graph? What are the limitations on memory, time? These are at least those questions that need to be answered in order to choose an "efficient" algorithm. If the task is just to go around all the vertices, without any conditions, then take any of the algorithms. I would take the search in depth, it seems to me easier, there it is more difficult to make a mistake. - Flowneee

1 answer 1

I answer a specific question with a specific answer - about one way I will say “recursive”, and about the second - non-recursively. And you absolutely correctly noticed about the task - it means an applied task to which you want to apply one of these algorithms.

  • 1) "about one way I will say" recursively ", but about the second - .... non-recursively" - it is not clear what you mean by that; 2) the applied task is to bypass all the vertices of the graph in any order that is written in the question - user247920
  • Search in depth - the classic implementation of this algorithm has a recursive form. - isnullxbh
  • As for the "efficiency" - for your task - it seems to make no sense to make a choice. Take any. - isnullxbh