Binary search tree insertion and search

Draw a binary search tree in VectorPaint: insertion, search and inorder traversal

Construct a binary search tree from seven distinct integers and check each parent, search path and traversal.

English translation of the Chinese original, translated on . Original publication dates, attribution, code and version notes are retained.

Construct a binary search tree from seven distinct integers and check each parent, search path and traversal.

Prepare the sequence and rules

Insert the fictional sequence 8, 3, 10, 1, 6, 14, 4 into an empty tree in that order. All values in a node’s left subtree are smaller, and all values in its right subtree are larger. Values here are distinct, so duplicate handling is outside this exercise. OpenStax describes both the at-most-two-child structure and the ordering constraint for entire subtrees. Write the sequence down before drawing.

Set up canvas and nodes

Create a landscape canvas in VectorPaint and save an editable original. Use the available ellipse, text and line controls; choose one consistent node size and leave room below three levels. Keep connectors and labels separately editable. Canvas dimensions are an exercise choice; use controls visible in your version and do not assume an automatic tree-layout feature.

Insert root 8

Draw a circle near the top center and label it 8. The first value in an empty tree becomes its root and has no parent; do not draw edges that do not yet exist. Every later insertion begins by comparing with the root, rather than placing a value in any empty area. Leave space on both sides for later branches.

Insert 3 and 10

Because 3 is less than 8, place it below left and connect it. Because 10 is greater than 8, place it below right and connect it. Center text within circles and stop lines at circle edges. Numeric comparisons, not merely available space, determine direction. Check that 3 is the root’s left child, 10 its right child and each has one edge to its parent.

Insert 1 and 6

For 1, compare with 8 and go left to 3; compare with 3 and place 1 to its left. For 6, again go left from 8 to 3, but place it on the right because 6 is greater than 3. The paths are 8→3→1 and 8→3→6. Both nodes remain in 8’s left subtree; 6 being greater than 3 does not put it to the right of 8.

Insert 14 and 4

Because 14 is greater than 8, go to 10; it is also greater than 10, so place it on the right. For 4, go left from 8 to 3, right from 3 to 6, then left from 6. The paths are 8→10→14 and 8→3→6→4. Leave space for 4’s lower level so connectors do not cross node 1 or labels.

Check whole subtrees

Check every node, not just its immediate parent-child pairs. The left subtree of 8 contains 3, 1, 6 and 4, all less than 8; the right contains 10 and 14, both greater. The right subtree of 3 contains 6 and 4, both greater than 3; 4 is less than its parent 6. Each node has at most two children and no third downward edge.

Highlight a successful search

On a copy, emphasize the edges for finding 4 in sequence: left from 8 to 3, right to 6, left to 4. Write L, R, L alongside; stop once the equal value is found. Preserve neutral connectors in the original. Color should not be the sole cue, so retain the written path for grayscale reading.

Check an unsuccessful search

In notes search for 7: it is less than 8, greater than 3, and greater than 6. The required right child of 6 is empty, so the search fails. Use an empty square or an “empty” label for the missing position; do not draw 7 as if inserted. Keep this path separate from the successful search so they are not mistaken for one operation.

Read the inorder result

Visit each node in the order left subtree, node, right subtree. The result is 1, 3, 4, 6, 8, 10, 14. Compare it with the sorted input; do not rely on merely scanning page positions. This traversal checks the example, not a claim that insertion order was sorted. If 4 appears before 3, revisit the order used for 3 and its right subtree.

Distinguish insertion from traversal

Insertion order builds the tree; inorder traversal reads an existing tree left, node, right. Do not reinsert 1, 3, 4, 6, 8, 10, 14 and call the result the same tree: under ordinary non-self-balancing insertion, ascending values form a rightward chain. Sketch the first three steps 1→3→4 on paper if useful, but keep the main diagram unchanged and do not claim all binary search trees balance automatically.

Provide a text alternative

Add a short structure list: children of 8 are left 3 and right 10; children of 3 are left 1 and right 6; 10 has only right 14; 6 has only left 4. Unlisted child positions are empty. This gives readers a way to check the structure without relying on colors or positions. An empty position is not the value zero. Cross-check it with the inorder result and save a dated copy for later review and comparison.

Polish the diagram

Add a short legend for root, nodes and edges, and state that distinct values were inserted in the given order. Hide guides and reduce the drawing to reading size; inspect node 4, direction labels and numbers for collisions. Move connectors to circle edges if they cross text. Do not swap children or change values for layout; changing a value requires comparing again from the root.

Save and troubleshoot

Save the editable original, then use an available share or export control to save a separate PNG or PDF. Reopen it and check the seven values, six parent-child edges and both search notes for clipping; the empty search marker is not a value node. If inorder output is not ascending, inspect whole-subtree constraints rather than editing the text alone. This guide uses public data-structure explanations and claims neither automatic tree construction nor a device test.

Probability tree without replacement; Conditional denominator table.

Checked 26 November 2026: OpenStax data structures; Apple public lookup. This is a manual drawing, not an automatic tree feature.