MCPcopy Index your code
hub / github.com/joowani/binarytree / properties

Method properties

binarytree/__init__.py:1487–1541  ·  view source on GitHub ↗

Return various properties of the binary tree. :return: Binary tree properties. :rtype: dict **Example**: .. doctest:: >>> from binarytree import Node >>> >>> root = Node(1) >>> root.left = Node(2) >>> roo

(self)

Source from the content-addressed store, hash-verified

1485
1486 @property
1487 def properties(self) -> Dict[str, Any]:
1488 """Return various properties of the binary tree.
1489
1490 :return: Binary tree properties.
1491 :rtype: dict
1492
1493 **Example**:
1494
1495 .. doctest::
1496
1497 >>> from binarytree import Node
1498 >>>
1499 >>> root = Node(1)
1500 >>> root.left = Node(2)
1501 >>> root.right = Node(3)
1502 >>> root.left.left = Node(4)
1503 >>> root.left.right = Node(5)
1504 >>> props = root.properties
1505 >>>
1506 >>> props['height'] # equivalent to root.height
1507 2
1508 >>> props['size'] # equivalent to root.size
1509 5
1510 >>> props['max_leaf_depth'] # equivalent to root.max_leaf_depth
1511 2
1512 >>> props['min_leaf_depth'] # equivalent to root.min_leaf_depth
1513 1
1514 >>> props['max_node_value'] # equivalent to root.max_node_value
1515 5
1516 >>> props['min_node_value'] # equivalent to root.min_node_value
1517 1
1518 >>> props['leaf_count'] # equivalent to root.leaf_count
1519 3
1520 >>> props['is_balanced'] # equivalent to root.is_balanced
1521 True
1522 >>> props['is_bst'] # equivalent to root.is_bst
1523 False
1524 >>> props['is_complete'] # equivalent to root.is_complete
1525 True
1526 >>> props['is_symmetric'] # equivalent to root.is_symmetric
1527 False
1528 >>> props['is_max_heap'] # equivalent to root.is_max_heap
1529 False
1530 >>> props['is_min_heap'] # equivalent to root.is_min_heap
1531 True
1532 >>> props['is_perfect'] # equivalent to root.is_perfect
1533 False
1534 >>> props['is_strict'] # equivalent to root.is_strict
1535 True
1536 """
1537 properties = _get_tree_properties(self).__dict__.copy()
1538 properties["is_balanced"] = _is_balanced(self) >= 0
1539 properties["is_bst"] = _is_bst(self)
1540 properties["is_symmetric"] = _is_symmetric(self)
1541 return properties
1542
1543 @property
1544 def inorder(self) -> List["Node"]:

Callers

nothing calls this directly

Calls 4

_get_tree_propertiesFunction · 0.85
_is_balancedFunction · 0.85
_is_bstFunction · 0.85
_is_symmetricFunction · 0.85

Tested by

no test coverage detected