Should I consider memmove() O(n) or O(1)?

北慕城南 提交于 2019-12-01 15:05:34

问题


this may be a silly question, but I want to calculate the complexity of one of my algorithms, and I am not sure what complexity to consider for the memmove() function.

Can you please help / explain ?

void * memmove ( void * destination, const void * source, size_t num );

So is the complexity O(num) or O(1). I suppose it's O(num), but I am not sure as I lack for now the understanding of what's going on under the hood.


回答1:


Since the running time of memmove increases in direct proportionality with the number of bytes it is required to move, it is O(n).




回答2:


What are you applying the memmove() operation to - selected elements in the algorithm or all of them? Are you applying memmove() to elements more than once?

Those are the things that will matter to the algorithm's complexity.

That answer may be different that the complexity of memmove() itself regarding the arrays of char elements that memmove() deals with (for which memmove() is an O(n) operation).



来源:https://stackoverflow.com/questions/2710002/should-i-consider-memmove-on-or-o1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!