Source: https://guthlabs.ai/docs/instruments/binary-tree-heap-visualizer-property-calculator/implementation/

instrument implementation / implementation-contract

# Binary Tree / Heap Visualizer & Property Calculator implementation

A source-bound implementation contract for Binary Tree / Heap Visualizer & Property Calculator; deployment and executable qualification remain separate.

Status: **VERIFIED_CLEAN**Lifecycle: **implementation-contract**

## Binding contract

This record describes what an executable surface must bind and validate. It does not claim that a public calculator, package, or production route is deployed.

**Record owner**: Guth Instruments

**Lifecycle**: verified-clean

**Evidence ID**: t6-098

**Effect**: Computation or source lookup only

## Input and validation requirements

- log2(0) causes an undefined-value or division/domain error unless the empty tree is handled before applying the formula.

- Using floor(log2(n)) for a non-complete tree gives an incorrect height; the implementation must compute the longest root-to-leaf path for arbitrary trees.

- A one-based heap-index implementation must use child indices 2i and 2i+1, while a zero-based implementation must use 2i+1 and 2i+2; mixing conventions can create invalid edges or missed checks.

- Duplicate BST values require an explicit policy, such as reject, always insert left, or always insert right.

- A balance factor needs a declared sign convention and empty-subtree height convention; otherwise reported values are ambiguous.

- Heap validation should handle missing children and should report which parent-child edge violates the selected min-heap or max-heap comparator.

- If arbitrary numeric strings, mixed units, NaN, or incomparable values are accepted, ordering and heap validation are not well-defined.

- The honest label is empty; the instrument should state the construction mode, height convention, balance-factor definition, duplicate policy, and that the complete-tree height shortcut is not applicable to arbitrary BSTs.

## Required corrections

No binding erratum is attached to this unique-name record. Implementers must still preserve the declared units, domain, and failure behavior.

## Inspectable interface fixture

The sample below is evidence for interface and validation tests, not a production implementation.

````
{
  "inputs": {
    "array": [
      1,
      3,
      2,
      7,
      6,
      5
    ],
    "tree_type": "min-heap",
    "construction": "level-order",
    "height_convention": "edges",
    "balance_convention": "left_height_minus_right_height"
  },
  "expected_outputs": {
    "nodes_by_level": [
      [
        1
      ],
      [
        3,
        2
      ],
      [
        7,
        6,
        5
      ]
    ],
    "height_edges": 2,
    "balance_factors_by_value": {
      "1": 0,
      "2": 1,
      "3": 0,
      "5": 0,
      "6": 0,
      "7": 0
    },
    "heap_valid": true,
    "violations": []
  },
  "working": "n=6. Complete-tree height = floor(log2(6)) = floor(2.5849625007) = 2 edges. Levels are [1], [3,2], [7,6,5], so there are 3 levels and height 3-1=2. Heap checks: 1<=3, 1<=2, 3<=7, 3<=6, and 2<=5; all are true. Balance factors: BF(1)=1-1=0; BF(3)=0-0=0; BF(2)=0-(-1)=1; each leaf has 0-0=0. Therefore the min-heap is valid."
}
````

## Other records

[01**Overview**](<https://guthlabs.ai/docs/instruments/binary-tree-heap-visualizer-property-calculator/>)[02**Mechanism**](<https://guthlabs.ai/docs/instruments/binary-tree-heap-visualizer-property-calculator/mechanism/>)[04**Qualification**](<https://guthlabs.ai/docs/instruments/binary-tree-heap-visualizer-property-calculator/qualification/>)

## Sources and evidence

These pointers bind the page to evidence. They do not grant authority or collapse verification into deployment.

- `VERIFIED_LEDGER.json`

- `evidence-tranche6/tranche6-results.json`
