在复杂性分析中,为什么 ++ 被认为是 2 个操作? [英] In Complexity Analysis why is ++ considered to be 2 operations?

查看:28
本文介绍了在复杂性分析中,为什么 ++ 被认为是 2 个操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的计算机科学 II 课上,教授认为 ++、--、*= 等是 2 个操作.但是,在程序集级别,这并不是真正的两个操作.有人可以解释一下还是只是为了简单起见?

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?

推荐答案

我实际上认为它是 3 个操作:读取、增量(或其他)、写入.这是假设它从某种共享内存读取到某种本地存储(例如寄存器或堆栈),在本地存储上操作,然后写回.

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.

这篇关于在复杂性分析中,为什么 ++ 被认为是 2 个操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆