计算2 ^ 5000的时间复杂度是多少?(What is the time complexity to calculate 2^5000?)

编程入门 行业动态 更新时间:2024-10-20 05:34:40
计算2 ^ 5000的时间复杂度是多少?(What is the time complexity to calculate 2^5000?)

计算2 ^ 5000的时间复杂度是多少?

我接近它,通过递归然后它导致O(N),其中N =数字的幂。 有没有办法减少这种时间复杂性?

What is the time complexity to calculate 2^5000 ?

I approached it, by recursion but then it leads to O(N) where N = power of a number. Is there any way to reduce this time complexity ?

最满意答案

我认为您对一般方法感兴趣,不仅仅是在这个给定的例子中。

您可以使用Log(N)运算通过平方逼近求幂来计算第N个整数幂

但请注意,数字2^N由大约N个二进制数字(位)组成,而在存储器中的简单写入是O(N)操作

I think that you are interested in general approach, not only in this given example.

You can calculate N-th integer power using Log(N) operations with exponentiation by squaring approach

But note that number 2^N consists of about N binary digits (bits) and simple writing in memory is O(N) operation

更多推荐

本文发布于:2023-04-29 12:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336356.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复杂度   时间   calculate   complexity   time

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!