复制输入的空间复杂性是什么?
我有一些字符串作为输入,我需要操纵他们的个体字符,这是通过首先将字符串分为字符数组来更有效地做到的。 简而言之,我的算法正在重复输入。它的空间复杂性是什么?
I have some strings as input and I need to manipulate their individual characters, which I do more efficiently by first splitting the strings into arrays of characters.
So in short, my algorithm is duplicating the input. What would be its space complexity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与原始问题相同的空间复杂性。
如果您的字符串中排列的n个字符的输入,则具有O(n)的空间复杂性。您要做的就是以某种不同的方式排列它们,并复制所需的空间:2N,因此具有O(2n)的复杂性。
但是,o(n)等同于o(kN),是k个常数。并不意味着两个问题都会消耗相同的内存,但是明智的复杂性是等效的。
The same space complexity as the original problem.
If you have an input of n characters arranged in strings, that carries a spatial complexity of O(n). All you do is arrange them in some different way and duplicating the space you need: 2n and thus having a complexity of O(2n).
However O(n) is equivalent to O(kn), being k any constant. Doesn't mean both problems consume the same memory but complexity wise they are equivalent.