复制输入的空间复杂性是什么?

发布于 2025-01-22 17:54:38 字数 85 浏览 2 评论 0原文

我有一些字符串作为输入,我需要操纵他们的个体字符,这是通过首先将字符串分为字符数组来更有效地做到的。 简而言之,我的算法正在重复输入。它的空间复杂性是什么?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏别ゝ 2025-01-29 17:54:38

与原始问题相同的空间复杂性。

如果您的字符串中排列的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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文