Skip to content

Commit fdd6361

Browse files
benjefferyjeromekelleher
authored andcommitted
Add note on time complexity
1 parent 066e3db commit fdd6361

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

python/tskit/jit/numba.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class TreeIndex:
9292
This class provides efficient forward and backward iteration through
9393
the trees in a tree sequence. It provides the tree interval,
9494
edge changes to create the current tree, along with its sites and mutations.
95+
A full pass over the trees using repeated `next` or `prev` requires O(E + M + S) time
96+
complexity.
9597
9698
It should not be instantiated directly, but is returned by the `tree_index` method
9799
of `NumbaTreeSequence`.
@@ -447,7 +449,9 @@ def tree_index(self):
447449

448450
def child_index(self):
449451
"""
450-
Create child index array for finding child edges of nodes.
452+
Create child index array for finding child edges of nodes. This operation
453+
requires a linear pass over the edge table and therefore has a time
454+
complexity of O(E).
451455
452456
:return: A numpy array (dtype=np.int32, shape=(num_nodes, 2)) where each row
453457
contains the [start, stop) range of edges where this node is the parent.
@@ -475,7 +479,9 @@ def child_index(self):
475479

476480
def parent_index(self):
477481
"""
478-
Create a :class:`ParentIndex` for finding parent edges of nodes.
482+
Create a :class:`ParentIndex` for finding parent edges of nodes. This
483+
operation requires sorting the edges by child ID and left coordinate,
484+
and therefore requires O(E log E) time complexity.
479485
480486
:return: A new parent index container that can be used to
481487
efficiently find all edges where a given node is the child.

0 commit comments

Comments
 (0)