This lesson focuses on how to construct the data structure you want, or to extend the capabilities of existing structures to achieve the specific functionality you want.
For example, design a dynamic structure that satisfies the function of finding the number of K-Large
the practice is to maintain the number of sub-nodes of each node to derive its rank without maintaining its rank, because dynamic operations make it difficult to maintain
Red-Black Tree insert operation 1. Tree Insert 2.rebalance
Build the basic flow of data structures you need to expand
1. Select a basic data structure such as a red-black tree
2. Decide which basic information to add to the node, such as implementing the query K-large function, the basic information that should be added is the sum of all the subtree nodes, rather than the rank of the node key value directly saved
3 Maintain insert + rotate/delete + rotate
4 encapsulation is a function that implements its function
later introduced a kind of interval tree, in fact, there are many related data structure, including line tree and its various variants, ranking tree, Chairman tree, etc., the main idea is to maintain some additional information to achieve the desired function, then I will update some examples in real time
"Introduction to Algorithms" The 11th lesson expanded data structure, dynamic ordered statistics and interval tree