简体   繁体   English

在 AVL 树上插入元素

[英]Insert elements on AVL Tree

A professor claims that the order in which a fixed set of elements is inserted into an AVL tree does not matter—the same AVL tree results every time.一位教授声称,将一组固定元素插入 AVL 树的顺序无关紧要——每次都会产生相同的 AVL 树。

Give a small example that proves that the professor is wrong.举一个小例子,证明教授错了。

As a trivial example consider the set with elements 1 & 2. Insert 1 then 2 and the root is 1 with 2 as a right child.作为一个简单的例子,考虑具有元素 1 和 2 的集合。插入 1 然后插入 2,根是 1,其中 2 作为右孩子。 Insert 2 then 1 and the root is 2 with 1 as the left child.插入 2 然后 1 和根是 2 与 1 作为左孩子。

You will get an AVL tree every time but elements can be in different locations based on the order they were inserted.您每次都会得到一个 AVL 树,但元素可以根据插入的顺序位于不同的位置。

Correct me if im wrong如我错了请纠正我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM