Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat are some alternatives to recursive search algorithms?
    primarykey
    data
    text
    <p>I am looking at alternatives to a deep search algorithm that I've been working on. My code is a bit too long to post here, but I've written a simplified version that captures the important aspects. First, I've created an object that I'll call 'BranchNode' that holds a few values as well as an array of other 'BranchNode' objects.</p> <pre><code>class BranchNode : IComparable&lt;BranchNode&gt; { public BranchNode(int depth, int parentValue, Random rnd) { _nodeDelta = rnd.Next(-100, 100); _depth = depth + 1; leafValue = parentValue + _nodeDelta; if (depth &lt; 10) { int children = rnd.Next(1, 10); branchNodes = new BranchNode[children]; for (int i = 0; i &lt; children; i++) { branchNodes[i] = new BranchNode(_depth, leafValue, rnd); } } } public int CompareTo(BranchNode other) { return other.leafValue.CompareTo(this.leafValue); } private int _nodeDelta; public BranchNode[] branchNodes; private int _depth; public int leafValue; } </code></pre> <p>In my actual program, I'm getting my data from elsewhere... but for this example, I'm just passing an instance of a Random object down the line that I'm using to generate values for each BranchNode... I'm also manually creating a depth of 10, whereas my actual data will have any number of generations.</p> <p>As a quick explanation of my goals, _nodeDelta contains a value that is assigned to each BranchNode. Each instance also maintains a leafValue that is equal to current BranchNode's _nodeDelta summed with the _nodeDeltas of all of it's ancestors. I am trying to find the largest leafValue of a BranchNode with no children.</p> <p>Currently, I am recursively transversing the heirarchy searching for BranchNodes whose child BranchNodes array is null (a.k.a: a 'childless' BranchNode), then comparing it's leafValue to that of the current highest leafValue. If it's larger, it becomes the benchmark and the search continues until it's looked at all BranchNodes.</p> <p>I can post my recursive search algorithm if it'd help, but it's pretty standard, and is working fine. My issue is, as expected, that for larger heirarchies, my algorithm takes a long while to transverse the entier structure.</p> <p>I was wondering if I had any other options that I could look into that may yield faster results... specificaly, I've been trying to wrap my head around linq, but I'm not even sure that it is built to do what I'm looking for, or if it'd be any faster. Are there other things that I should be looking into as well?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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