Applications of red-black trees

后端 未结 4 1887
夕颜
夕颜 2021-01-30 06:35

What are the applications of red-black (RB) trees? Is there any application where only RB Trees can be used and no other data structures?

4条回答
  •  生来不讨喜
    2021-01-30 07:19

    There is no such rule like red black can only be used in a particular case it depends upon the application in cases like when You have to build the tree only once and you have to query it many times then you can go for a AVL tree because in AVL tree searching is quite fast.. But it is strictly balanced so insertion and deletion may take some time AVl tree may be used for language dictionery where You have to build the data structure just once and the red black tree is used in the Completely Fair Scheduler used in current Linux kernels now a days..

    the constraints applied on the red black tree also enforce the point that that that the path from the root to the furthest leaf is no more than twice as long as the path from the root to the nearest leaf.

    BTW you can look for the various seach and insert etc time required for a red black tree down here

            Average     Worst case
    
    Space   O(n)        O(n) 
    
    Search  O(log n)    O(log n)
    
    Insert  O(log n)    O(log n)
    
    Delete  O(log n)    O(log n)
    

提交回复
热议问题