Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Code would help. What data structure are you using to store the partial or candidate solutions? You say your using a queue to store nodes to be examined, but really the objects stored in the queue should wrap some structure (e.g. <code>List</code>) that indicates the nodes traversed to get to the node to be examined. So, instead of simple <code>Node</code>s being stored in the queue, some more complex object would be needed to make available the information necessary to know the complete path taken to that point. A simple node would only have information about itself, and it's children. But if you're examining node X, you also need to know how you arrived to node X. Just knowing node X isn't enough, and the only way (I know of) to know the path taken to node X is to store the path in the object that represents a "partial solution" or "candidate solution". If this is done, then finding the length of the path is trivial, because it's just the length of this list (or whichever data structure chosen). Hope I'm making some sense here. If not, post code and I'll take a look.</p> <p><strong>EDIT</strong><br/></p> <p>These bits of code help show what I mean (they're by no means complete):</p> <pre><code>public class Solution { List&lt;Node&gt; path; } Queue&lt;Solution&gt; q; </code></pre> <p>NOT</p> <pre><code>Queue&lt;Node&gt; q; </code></pre> <p><strong>EDIT 2</strong><br/></p> <p>If all you need is the length of the path, and not the path, per se, then try something like this:</p> <pre><code>public class Solution { Node node; // whatever represents a node in you algorithm. int len; // the length of the path to this node. } // Your queue: LinkedList&lt;Solution&gt; q; </code></pre> <p>With this, before enqueuing a candidate solution (node), you do something like:</p> <pre><code>Solution sol = new Solution(); sol.node = childNodeToEnqueue; sol.len = parentNode.len + 1; q.add(sol); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload