pre-order traversal of a Minimum spanning tree

╄→гoц情女王★ 提交于 2019-12-11 03:01:44

问题


Is there any way to print the pre-order traversal of the output given by MST (using Kruskal or Prim's algorithm). I have a confusion because the output may be or not a binary tree always. So, how the pre-order traversal is possible here? Can a normal DFS do the task?


回答1:


The main issue when working with this kind of problem is the ambiguity of the word tree in algorithmic problems. There are two main definitions (those may in fact differ slightly):

  1. A tree is an acyclic connected (undirected) graph.
  2. A tree is basically a set of nodes, each one having a father (except one node, called the root node) and the list of sons for each node is ordered.

However, you have to work with the second definition to assume that the concept of preoder traversal is well-defined (i.e. unique).

A spanning tree, though, is only a tree in the first meaning. In particular, you have to pick out a root node and some order for the sons. Afterwards, a DFS will give you a preoder traversal indeed.



来源:https://stackoverflow.com/questions/39401245/pre-order-traversal-of-a-minimum-spanning-tree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!