Need Help with understanding the Time complexity of the following code in c++?

Revision en1, by zenwraight, 2023-10-25 05:01:13

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:-

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 :)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English zenwraight 2023-10-25 20:48:19 118
en1 English zenwraight 2023-10-25 05:01:13 637 Initial revision (published)