Preference between AVL tree and 2-3 tree

can someone tell me if using AVL is preferable to using 2-3 trees or vice versa and why so?

thanks

+4
source share
2 answers

My preferences among the different tastes of balanced binary trees are AVL trees. They are easier to program than any alternatives (see My implementation here and here , and note that even deleting is not particularly difficult) because there are fewer cases to consider, they provide a very slightly faster search (because they are more strictly balanced than alternatives) and there are no hidden worst cases or amortized time frames.

I also prefer AVL trees for hash tables. I know that the complexity of the hash tables with the expected time exceeds the guaranteed time complexity of the AVL trees, but in practice, constant factors make the two data structures generally competitive, and there are no problems associated with some unexpected data that cause poor behavior. In addition, I often find that once during the life of a program, in a situation that is not expected, when the initial selection of the hash table seemed correct, I need the data in sorted order, so I end up rewriting the program to use the Tree AVL instead of a hash table; do it enough time and you will find out that you can also start with AVL trees.

If your keys are strings, triple search attempts offer a reasonable alternative to AVL trees.

+3
source

AVL tree

The AVL tree is a self-balancing binary search tree invented by G. M. Edelson-Welsky and E. M. Landisin 1962. The tree is called AVL in honor of its inventors. In an AVL tree, the heights of two node subtrees may differ by no more than one. Due to this property, the AVL tree is also known as a height-balanced tree.

2-3 tree

In 2-3 trees, each interior node has two or three children. Nodes with two children are called 2 nodes. 2-nodes have one data value and two children. Nodes with three children are called 3-nodes. 3-nodes have two data values ​​and three children (left child, middle child and right child).

Example: 2-3 Tree

This means that tree 2-3 is not a binary tree. In this tree, all leaf nodes are on the same level (lower level).

Here you can find the difference between almost all types of trees in the data structure ... https://knowshares.wordpress.com/2017/01/01/difference-binary-binarysearch-avl-2-3-b-trees/

0
source

Source: https://habr.com/ru/post/1389267/


All Articles