平面数据到有向图树的最佳排序和格式化算法

时间:2014-06-24 19:23:03

标签: java algorithm parsing graph tree-traversal

给出这样的平坦数据:

01001, Butter, salted
01002, Butter, whipped, with salt
01145, Butter, without salt
04601, Butter, light, stick, with salt
04602, Butter, light, stick, without salt

转换成这个的最佳方法是什么:

Butter (01001, 01002, 01145, 04601, 04602) -> salted (01001)
                     -> whipped (01002) -> with salt (01002)
                     -> without salt (01145) 
                     -> light (04601, 04602) -> stick  (04601, 04602) -> with salt (04601)
                                                                      -> without salt (04602)

我首先考虑递归排序,但我意识到可能会有很多字符串比较效率。

0 个答案:

没有答案