Skip to content

Commit

Permalink
Fixing node_number_at_depth for empty trees.
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Scrimshaw committed Feb 2, 2020
1 parent 87c3057 commit aaa0581
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/sage/combinat/abstract_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,21 @@ def node_number_at_depth(self, depth):
o
sage: [T.node_number_at_depth(i) for i in range(6)]
[1, 3, 4, 2, 1, 0]
TESTS:
Check that the empty tree has no nodes (:trac:`29134`)::
sage: T = BinaryTree()
sage: T
.
sage: T.is_empty()
True
sage: [T.node_number_at_depth(i) for i in range(3)]
[0, 0, 0]
"""
if self.is_empty():
return Integer(0)
if depth == 0:
return Integer(1)
return sum(son.node_number_at_depth(depth - 1) for son in self)
Expand Down

0 comments on commit aaa0581

Please sign in to comment.