ⓘ 2–3 tree. In computer science, a 2–3 tree is a tree data structure, where every node with children has either two children and one data element or three childre ..

                                     

ⓘ 2–3 tree

In computer science, a 2–3 tree is a tree data structure, where every node with children has either two children and one data element or three children and two data elements. According to Knuth, "a B-tree of order 3 is a 2-3 tree." Nodes on the outside of the tree have no children and one or two data elements. 2−3 trees were invented by John Hopcroft in 1970.

2–3 trees are balanced, meaning that each right, center, and left subtree contains the same or close to the same amount of data.

                                     

1. Definitions

We say that an internal node is a 2-node if it has one data element and two children.

We say that an internal node is a 3-node if it has two data elements and three children.

We say that T is a 2–3 tree if and only if one of the following statements hold:

  • T is a 2-node with data element a. If T has left child L and right child R, then
  • T is empty. In other words, T does not have any nodes.
  • L and R are non-empty 2–3 trees of the same height;
  • a is greater than each element in L ; and
  • a is less than or equal to each data element in R.
  • T is a 3-node with data elements a and b, where a < b. If T has left child L, middle child M, and right child R, then
  • L, M, and R are non-empty 2–3 trees of equal height;
  • b is greater than each data element in M and less than or equal to each data element in R.
  • a is greater than each data element in L and less than or equal to each data element in M ; and
                                     

2.1. Operations Searching

Searching for an item in a 2–3 tree is similar to searching for an item in a binary search tree. Since the data elements in each node are ordered, a search function will be directed to the correct subtree and eventually to the correct node which contains the item.

  • Suppose r is a 2-node with left child L and right child R. Let be the data element in r. There are three cases
  • Let r be the root of T.
  • If d < e {\displaystyle d > e {\displaystyle d> e}, then set T to R and go back to step 2.
  • Suppose r is a leaf. If d is not in r, then d is not in T. Otherwise, d is in T. In particular, d can be found at a leaf node. We need no further steps and were done.
  • If d is equal to e, then weve found d in T and were done.
  • Let T be a 2–3 tree and d be the data element we want to find. If T is empty, then d is not in T and were done.
  • Suppose r is a 3-node with left child L, middle child M, and right child R. Let a and b be the two data elements of r, where a < b {\displaystyle a
Free and no ads
no need to download or install

Pino - logical board game which is based on tactics and strategy. In general this is a remix of chess, checkers and corners. The game develops imagination, concentration, teaches how to solve tasks, plan their own actions and of course to think logically. It does not matter how much pieces you have, the main thing is how they are placement!

online intellectual game →