Iv'e been struggling a lot with this one. I am looking for a data-structure (could be a modification of an existing type of data-structure, or a combination of more than one data-structure), which supports the following methods, all with time complexity (at worst-case) of $O(log(n))$:
- Insert(v) - insert v to the structure
- search(v) - search for v
- delete(v) - delete node with value v
- updateKeys(x,v) - for each node with a value greater then x, add v to it's value, where v is a positive number.
For example, if I had the following set of elements: ${1,2,5,8,10,15,20}$
, using updateKeys
the following way: $ updateKeys(10,5) $ would change the set to : $ {1,2,5,8,15,20,25} $.
Well, I had a lot in my mind. Basically, my assignment is on the following data-structures:
Hash tables - which sounded good at first, but I couldn't think of a way to find all elements larger than or equal to x.
AVL tree - it does support the basic methods with this complexity, but in order to find which elements are larger, I need to search through all tree which can cost more than $ log(n) $. Further more, I can mess the tree up if I for instance make a left son be larger than it's parent.
- A combination of the two above - looked promising at first, but again, I couldn't find a way to find those elements.
Heap - for some reason it sounds like a good direction since I have some sort of order, but update the values with log(n) time? seems impossible.
Skip list - here I thought about using skip list since the most bottom layer is sorted in increasing order, so I thought about finding the minimum value larger than x, and then update all of it's followers from the right. Sounds good, but it is definitely not within $ O(log(n)) $, since for the following set ${1,2,3,4...10}$, and for $ x=1 $, I need to iterate 10 numbers, which is $ O(n) $
We also studied B-trees, ADT structures...
Then, almost hopeless, I started reading about data structures that weren't even taught in our course, such as range trees, BIT trees and so on.For some reason, some of them seemed suitable for this purpose, but since it's not in our syllabus, I don't think we are even allowed to use them.
Thanks in advance.