在复杂度分析中,为什么++被视为2个运算? [英] In Complexity Analysis why is ++ considered to be 2 operations?

查看:67
本文介绍了在复杂度分析中,为什么++被视为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天全站免登陆