I basically need a way of guaranteed O(log n) deletion. Can this be done with a binary tree, or is it always worst case O(n)?
What if I balance the tree everytime?
please help
You need a balanced binary tree for the guarantee to work. Red Black Trees are an example of the balanced tree structure and the implementation is not too hard.
And here is a nice lecture for that ..
If you are looking for a balanced binary tree, you could use the "heap"
You need a Binary Search Tree
As the wiki page above said:
thus in the worst case it requires time proportional to the height of the tree
which means if you can make it always balanced, you can get O(logN) for deletion
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.