zenwraight's blog

By zenwraight, history, 12 months ago, In English

Hi Folks, I came across a piece of code and I am having a hard time figuring out the time complexity of the code. Here is the code:-

This is just for example purpose, basically the q has N values, just for example purpose, I am considering N=3.

map<string, queue<int>> m;
queue<int> q;
q.push(0);
q.push(1);
q.push(2);
m["key"] = q;
queue<int> temp = m["key"];

I want to know will the time complexity of this piece of code be O(1) or O(N)?

My understanding says that it's O(N) because of line queue<int> temp = m["key"] , as we copy the queue to a new variable.

Any pointers or help is greatly appreciated.

Thanks Folks :)

Full text and comments »

  • Vote: I like it
  • -16
  • Vote: I do not like it