Tango Tree Data Structure
Tango Tree is an online algorithm. It is a type of binary search tree. It is better than the offline weight balanced binary search tree as it achieves a competitive ratio of
as compared to competitive ratio of
of offline weight balanced binary search tree. It takes only
of additional bits of memory at every node of the tree to increase the performance over weight balanced binary search tree.
Tango tree is conceptually a tree of trees as it partitions a binary search tree into preferred paths and non preferred paths and these preferred paths are themselves stored in the form of auxiliary trees.
Preferred child and Preferred Paths
Preferred child of any node of Tango tree is defined as the most recently touched child by a normal binary search tree lookup technique. Elaborating more on preferred child let us assume a subtree T rooted at node n with right child as p and left child as q. Call p as the preferred child of n if most recently accessed node of subtree rooted at n is present in the subtree rooted at p.
A Preferred path is defined as the path starting from root node and following all the preferred children along a path to reach a leaf node.

Tango Tree
Auxiliary Trees for Preferred Paths
A preferred path is represented by storing the nodes of the preferred path in a balanced binary search tree specifically red black tree. Then, for every non-leaf node of path P there is a non-preferred child
. This non preferred child acts as the root of the new auxiliary tree and then attach this new auxiliary tree rooted at
to its parent and in this way, it is easy to link the auxiliary trees together. There is also option to store some extra information in each node of the auxiliary tree as per our own needs like minimum depth of the nodes in the subtree below it, etc.
Operations on Tango Tree
The two most common operations on Tango Trees are Searching and Updating
- Updating in a Tango Tree
- Cut process
- Join process
- Searching in a tango tree
- Applications of tree data structure
- Overview of Data Structures | Set 3 (Graph, Trie, Segment Tree and Suffix Tree)
- Gap Buffer Data Structure
- Advantages of Trie Data Structure
- Trie Data Structure using smart pointer and OOP in C++
- Data Structure for Dictionary and Spell Checker?
- Design an efficient data structure for given operations
- Ropes Data Structure (Fast String Concatenation)
- Dynamic Disjoint Set Data Structure for large range values
- Design a data structure that supports insert, delete, search and getRandom in constant time
- Overview of Data Structures | Set 2 (Binary Tree, BST, Heap and Hash)
- Check if a given Binary Tree is height balanced like a Red-Black Tree
- Tournament Tree (Winner Tree) and Binary Heap
- Two Dimensional Binary Indexed Tree or Fenwick Tree
- Binary Indexed Tree or Fenwick Tree
It needs to maintain the structure of the Tango Tree because of constant updates as the preferred child of the nodes changes after every search. Whenever the preferred changes the preferred path is divided into two parts at the particular node that has changed and the top part of the preferred path needs to be attached to the end of another preferred path. For this purpose, divide the update into two parts:
In this operation, divide the preferred path into two paths at the a given node – top part and bottom part. Top part is the auxiliary tree containing the nodes above a certain node’ level and the Bottom part becomes an auxiliary tree containing node below the given node’s level.
In this operation we combine the two auxiliary trees together. But they can only be combined if the bottom node of one of the combining trees is the parent of the top node of the other combining tree. This join operation uses the concatenation operation of red black trees. There exists two nodes in the top path such that a node is said to be in the bottom path if the its key value exists between these two nodes. To concatenate, we simply split the top path between these two nodes and then join the two resulting auxiliary trees to the bottom path and our resulting auxiliary tree is ready.
To search in a Tango tree we simply carry out the search in the conceptual binary search tree. First search the preferred path by searching its auxiliary tree. If the node cannot be found in the given auxiliary tree then, search the auxiliary tree of the next path and so on until search of the entire tree or could not find the desired node.
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



