Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>These kind of "mass modification" operations are sometimes called <em>bulk updates</em>. Of course, the details will vary depending on exactly what kind of data structure you are working with and what kind of modifications you are trying to perform.</p> <p>Typical kinds of operations might include "delete all values satisfying some condition" or "increment the values associated with all the keys in this list". Frequently, these operations can be performed in a single walk over the entire structure, taking O(n) time.</p> <p>You seem to be concerned about the memory allocation involved in creating "1000's of new roots". Typical allocation for performing the operations one at a time would be O(k log n), where k is the number of nodes being modified. Typical allocation for performing the single walk over the entire structure would be O(n). Which is better depends on k and n.</p> <p>In some cases, you can decrease the amount of allocation--at the cost of more complicated code--by paying special attention to when changes occur. For example, if you have a recursive algorithm that returns a tree, you might modify the algorithm to return a tree <em>together with</em> a boolean indicating whether anything has changed. The algorithm could then check those booleans before allocating a new node to see whether the old node can safely be reused. However, people don't usually bother with this extra check unless and until they have evidence that the extra memory allocation is actually a problem.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COThanks for the great info. I wasn't considering walking over the entire structure. I added an example in the question. It seems to me that this example would have a much smaller memory footprint than the 1 by 1 approach. With splitting the list at each branch, it might be similar to O(k log n) for search, but each node that is updated (including ancestor nodes) is updated only once. 1 by 1 case: (k log n) to search for each node, but then another (k * avg depth) for updating ancestors (some repeatedly). In the question example, wouldn't that be reduced significantly?
      singulars
    2. COSure, your new binary tree example is essentially what I was referring to as walking the entire structure, because in general it will make recursive calls down both sides of the tree. Of course, in special cases, you may be able to stop early and avoid traversing parts of the tree. In other cases, you may still need to traverse part of the tree only to find that no changes actually happened in that part of the tree. That's when the extra boolean return value I mentioned might be useful if you want to avoid unnecessary allocation.
      singulars
    3. COYou only walk down a branch if there are nodes to be updated that match that branch. It searches the exact same way as the 1 by 1 case, but it does all k searches at the same time. So you'll never need to return a boolean about whether it updated or not because you would not have gone down that branch to begin with unless it would be updated.
      singulars
 

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