Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Complexity Analysis why is ++ considered to be 2 operations?

In my Computer Science II class, the professor considers ++,--,*=, etc. to be 2 operations. However, at the Assembly level this is not really two operations. Can someone explain or is this just for the sake of simplicity?

like image 283
dr.manhattan Avatar asked Nov 30 '22 12:11

dr.manhattan


1 Answers

I'd actually consider it to be 3 operations: read, increment (or whatever), write. That's assuming it's reading from some sort of shared memory into some sort of local storage (e.g. register or stack), operating on the local storage, then writing back.

How many operations it is at assembly level will depend on what you're incrementing, the platform, the hardware etc.

like image 167
Jon Skeet Avatar answered Dec 04 '22 12:12

Jon Skeet