TTreeSentinel
Workflows

Coding workflows · Strict binary-search-tree ordering

03
Built around your work

A concrete starting point

Validate integer search-tree nodes with two child references. Check empty trees and ancestor bounds, returning false for duplicate keys while rejecting cycles, shared children, malformed nodes or over 1000 nodes.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Strict binary-search-tree ordering

A concrete starting point
def is_strict_bst(root):
    pending, seen, checks = [(root, None, None)], set(), []
    while pending:
        node, low, high = pending.pop()
        if node is None:
            continue
        if type(node) is not list or len(node) != 3 or type(node[0]) is not int:
            raise ValueError("tree.node")
        if id(node) in seen or len(seen) == 1000:
            raise ValueError("tree.structure")
        seen.add(id(node))
        value, left, right = node
        checks.append((value, low, high))
        pending.extend([(right, value, high), (left, low, value)])
    return all((low is None or low < value) and
               (high is None or value < high) for value, low, high in checks)

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗