Muhammad Ahmad Mujtaba Muhammad Ahmad Mujtaba - 10 months ago 60
C++ Question

What is the meaning of statement XYZ while learning space-time complexity?

I am reading data structures and I am following book "Fundamentals of data structures in C++" - E. Horowitz, S. Sahni & D. Mehta.

While reading rules for step counts in time complexity, I am stuck at the following statement.
Can anyone please explain me the following paragraph especially bold literals.

The assignment statement variable = expression has a step count equal to that expression unless the size of variable is a function of instance characteristics.

Answer Source

The non-bold part is straight-forward: the code of an assignment is at a minimum the cost of computing what is to be assigned. The bold part is simply saying that if, once you have finished that calculation, the amount of work to assign that value is not a constant (that is, it is a function of the problem size), then you have to take that into account as well.

For example, how long it takes to assign a value to an integer variable would be a constant, while copying a string won't be if its length is determined by the size of the problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download