你的私隱選擇

KiwiBee 使用 Google Analytics、Google Ads 及 Meta Pixel 的可選 Cookie,以了解成年訪客、統計已完成的註冊及改善推廣活動。必要 Cookie 會一直保持啟用。 OpenAI 的 ChatGPT 廣告像素亦會在您同意廣告追蹤後衡量頁面瀏覽及已提交的查詢,並可能使用經雜湊處理的聯絡資料作配對。 私隱政策

跳到主要內容

Binary Search Tree & AVL 3D

  • 數學
—

關於這個模擬實驗

Binary Search Tree & AVL 3D visualizes hierarchical data structures in three-dimensional space. Every node displays its integer key and live AVL balance factor BF = height(Left) − height(Right), color-coded emerald for balanced nodes and coral red when |BF| exceeds 1. A glowing gold comparison orb hops down the tree from the root, testing whether the target key is smaller (go left) or larger (go right) than each ancestor. Students can switch between Sorted Skewed Input, Balanced Input, and Random Keys, click any node to measure exact search comparisons, and toggle Auto-balance AVL rotations to see LL, RR, LR, and RL rotations keep tree height logarithmic.

學生可以探索什麼

  • Select Sorted Skewed Input and turn off Auto-balance AVL rotations to see the keys 10, 20, 30... form a degenerate diagonal chain of height 7.
  • Turn Auto-balance AVL rotations back on and watch the tree immediately fold into a balanced 3-level pyramid of height 3 with BF = 0 everywhere!
  • Click any node sphere in the 3D tree to launch the gold comparison orb from the root and count how many steps it takes to reach that key.
  • Press Insert Next Key repeatedly to watch new numbers drop into position and trigger automatic single or double AVL rotations.
  • Drag any node in 3D space to inspect its left and right subtrees, then release to watch it spring back into layout.

學習目標

  1. 1State the Binary Search Tree ordering invariant: all keys in the left subtree are smaller than the parent, and all keys in the right subtree are larger.
  2. 2Explain why inserting sorted keys into an unbalanced BST degrades search time from O(log n) to O(n).
  3. 3Compute the balance factor BF = height(L) − height(R) of any tree node and identify when an AVL rotation is required.
  4. 4Compare the worst-case number of search comparisons in a balanced AVL tree versus a skewed BST.

教師常問的問題

What makes a Binary Search Tree (BST) fast for searching?

At every node, the BST invariant tells you whether the target key must lie in the left subtree or the right subtree. In a balanced tree, each comparison eliminates half of the remaining nodes, requiring at most log₂(n) steps.

What is the worst-case scenario for a standard BST?

If keys are inserted in ascending or descending sorted order (such as 10, 20, 30, 40...), every new key attaches as a right child. The tree degenerates into a linked list of height n, slowing searches down to O(n).

How does an AVL tree prevent the tree from becoming skewed?

Named after inventors Adelson-Velsky and Landis (1962), an AVL tree tracks each node's balance factor BF = height(L) − height(R). Whenever an insertion causes |BF| to reach 2, the tree performs a local Left or Right rotation in O(1) time to restore |BF| ≤ 1.

Why does the simulation color some nodes green, cyan, and red?

Emerald green nodes have perfectly equal left and right subtree heights (BF = 0), cyan nodes differ by one level (|BF| = 1, still valid AVL), and red nodes have |BF| ≥ 2, indicating an unbalanced subtree that needs rotation.

嵌入這個模擬實驗

免費嵌入你的學習平台、網誌或班級網頁。

<iframe src="https://kiwibee.io/zh/simulations/binary-search-tree-avl-3d-3d-simulation/embed" title="Binary Search Tree &amp; AVL 3D | KiwiBee" loading="lazy" allowfullscreen style="width:100%;height:min(70vh,620px);min-height:420px;border:0;border-radius:16px"></iframe>

把互動科學帶進你的課堂

KiwiBee 的免費教師工作空間,把備課、工作紙、課堂工具和成績冊集中在同一處。

免費開始,建立你的第一個班別

或了解教師工作空間 →