Depending on how many paragraphs you have, brute force may work:
If the number of paragraphs is very large, the number of combinations may exceed your processing capabilities. Like I said, brute force :-)
Alternate solution
Does this reduce to a form of the spanning tree problem? Perhaps if you would arrange set of graphs with two types of nodes (paragraphs - P, and words - W) where W are adjacent only to the containing P, and P is adjacent only to the W it contains, that you could
The sum of those depths (and the associated P nodes on those paths) should be your ideal list of paragraphs.
I think (still have not had coffee this AM).
Update: Given the updated information on the number of words and paragraphs, spanning tree may not be the best solution. Perhaps I will play with this and see if I can find the time to drop what is in my head down on paper.
Update 2: This algorithm is not suitable for large quantities of P from a big-O standpoint. If I have it right, it comes down to something along the lines of O(W * 2^P). The first pass on each connected graph would need to try all combinations of P, with a maximum depth of W. Perhaps the upper bound can be reduced, but not at my current coffee levels.
P.S. I have had problems this complex for homework. Perhaps not 100 level homework, but these problems do exist in upper level courses, and there are people who try to fake their way even at that level. So please, excuse some cynicism and a lack of desire from some to provide a full solution.
--MidLifeXis
In reply to Re: Help required in optimizing the output (PERL)
by MidLifeXis
in thread Help required in optimizing the output (PERL)
by randomid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |