Draft:Zip Tree

From Wikipedia, the free encyclopedia
  • Comment: Invented 2018 but only one source after 2018 KylieTastic (talk) 19:23, 5 March 2024 (UTC)

AVL tree
TypeTree
Invented2018
Invented byRobert E. Tarjan, Caleb C. Levy and Stephen Timmel
Complexities in big O notation
Space complexity
Space
Time complexity
Function Amortized Worst Case
Search .[1] [1]
Insert [1] [1]
Delete [1] [1]

In computer science, zip trees[1] are a type of randomized binary search tree which each node in a zip tree is assigned a numeric rank, with the tree maintaining a max-heap order based on these ranks.

This structure allows for efficient insertions and deletions without the need for rotations, using a process called zipping and unzipping. The rank of each node is randomly chosen from a geometric distribution, allowing for a compact representation of the tree. Zip trees require only bits to represent the largest rank in an n-node binary search tree.

Zip trees closely resemble two well-known data structures: the treap[2] and the skip list[3]

Definition[edit]

Spine[edit]

The spine of a node refers to a specific path originating from that node. The left spine is defined by the sequence of nodes reached by consecutively following the left child from a given node x until reaching the node with the smallest key within x's subtree. Conversely, the right spine is established by tracing the path through right children from x, ending at the node with the largest key in x's subtree.

Property[edit]

The expected rank of the root in a zip tree is at most .

For any c > 0, the root rank is at most .

Operations[edit]

Zip trees are characterized by three principal operations: insertion, deletion, and search.

Search[edit]

Searching for a specific value in a zip tree can be done the same way as that of any binary search tree. The running time complexity of a zip tree search is O(h) where h is the height of the tree.

Insert[edit]

To insert a new node x, the tree is searched to locate the node y that x will replace. This is determined by the condition that y's rank is less than or equal to x's rank, with a strict inequality if y's key is less than x's key.

Following this, the search path for x is split into two paths: P, containing nodes with keys less than x's key, and Q, containing nodes with keys greater than x's key. The process of splitting these paths is known as "unzipping".

The top node of P becomes x's left child, and the top node of Q becomes its right child. If y had a parent z before the insertion, x is made a child of z, replacing y. If y was the root, x becomes the new root​

Delete[edit]

Deletion is the inverse of insertion. To delete a node x, we first do a search for the node x to be deleted.

Let P and Q be the right spine of the left subtree of x and the left spine of the right subtree of x. Zip P and Q to form a single path R by merging them from top to bottom in non-increasing rank order, breaking a tie in favour of the smaller key. Zipping preserves the left subtrees of the nodes on P and the right subtrees of the nodes on Q.

Finally, if x had a parent z, make the top node of R(or null if R is empty) the left or right child of z, depending on whether the key of x is less than or greater than that of z, respectively (the top node of R replaces x as a child of z); if x is the root, make the top node of R the root.

Adventages[edit]

The advantages of zip trees over similar data structures like treap can be summarized in terms of operational simplicity and space efficiency[4]:

Operational Simplicity: Zip trees employ straightforward "zip" and "unzip" operations for insertions and deletions, which are conceptually simpler than the sequences of rotations used in treaps. This simplicity potentially makes zip trees easier to understand, implement, and maintain, reducing the cognitive load associated with complex rotation sequences found in other tree structures.

Space Efficiency and Structure: Zip trees utilize random ranks for organizing keys, similar to treaps. However, the ranks in zip trees require only bits each, in contrast to the bits required for key labels in treaps. This reduced bit requirement for ranks translates into more space-efficient storage of tree nodes. Furthermore, zip trees are topologically isomorphic to skip lists, meaning they share the same overall structure but achieve this with less space, further enhancing their efficiency.


References[edit]

  1. ^ a b c d e f g Tarjan Levy Timmel (2021). "Zip Trees". ACM Transactions on Algorithms. 17 (4): 1–12. arXiv:1806.06726. doi:10.1145/3476830.
  2. ^ Aragon, R.S. (1996) ‘Randomized search trees’, Algorithmica, 16(4–5), pp. 464–497. doi:10.1007/s004539900061.
  3. ^ WilliamPugh.“Gila, O., Goodrich, M.T. and Tarjan, R.E. (2023) ‘Zip-zip trees: Making zip trees more balanced, biased, compact, or persistent’, Lecture Notes in Computer Science, pp. 474–492. doi:10.1007/978-3-031-38906-1_31.
  4. ^ Gila, O., Goodrich, M.T. and Tarjan, R.E. (2023) ‘Zip-zip trees: Making zip trees more balanced, biased, compact, or persistent’, Lecture Notes in Computer Science, pp. 474–492. doi:10.1007/978-3-031-38906-1_31.