node.py

Node implementation for Red-Black Tree data structure.

This module defines the Node class that represents individual nodes in a Red-Black Tree. Each node contains data and maintains the tree’s structural properties including color, parent-child relationships, and black height for efficient tree balancing operations.

Classes

Node

Represents a single node in a Red-Black Tree with all necessary attributes for maintaining tree balance and performing tree operations.

class node.Node(data: object, color: int, parent: Node | None, left: Node | None, right: Node | None)[source]

Bases: object

Implements a node in a red-black tree

_data

Value of the node.

_color

Color of the node. (1: black, 0: red)

Type:

int

_parent

Parent of this node.

Type:

Node

_left

Left child of this node.

Type:

Node

_right

Right child of this node.

Type:

Node

_black_height

Black height of the node.

property black_height: int

Returns the black height of the node. :returns: The black height of the node. :rtype: int

property color: int

Returns the node’s color :returns: Color of the node (1: black, 0: red) :rtype: int

property data

Returns the node’s value.

property left

Returns the left child of the node

property parent

Returns the node’s parent.

property right

Returns the node’s right child.

update_black_height() int[source]

Updates the black_height of the node, also telling its parent to update if it changes :returns: The updated black height of the node. :rtype: int