Increasing all elements by integer x in O(n) in a program possibility?

Viewed 94

So I have stumbled upon a problem to solve:

I need to create a data structure that will have a set of integers. It needs to have methods: The class is named:

class structure

methods:

void structure::new(); //creates an empty set

void structure::insert(int x); //inserts an integer x into the set

bool structure::isElement(int x); //checks if x is in the set

void structure::increaseBy(int x); // increases all elements in set by x

I guess this one is a homework question.

But i just want an opinion what data structure is the best to use in this implementation.

And how can i create the last method that would increase all elements by x in O(1) times, at first it seems like impossible. Even if there are some c++ operators that have a functionality like that, wouldn't they have the same complexity?

I mean i could use a vector, array, even some linked list, set or similar structures.

So the problems isn't with first three methods, they are pretty easy to do, and also it is okay to use O(n) for the last one, but it's not "full points" unless it's O(1) time complexity. So is there a way to do it? Any hints would be helpful, and also I apologize if i made a mistake in creating this question it's my first time posting in stackoverflow.com, i was only using/posting math.stackexchange.com until now, so any advice would be appreciated as well.

Thank you in advance.

2 Answers
Related