Java中Integer.toBinaryString()的时间复杂度 [英] Time complexity of Integer.toBinaryString() in Java

查看:80
本文介绍了Java中Integer.toBinaryString()的时间复杂度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Integer.toBinaryString()的时间复杂度.

I want to know the time complexity of Integer.toBinaryString().

推荐答案

有两种查看方式:

  • Integer.toBinaryString(n)产生长度为ceiling(log2(n))的字符串.该计算将花费与log(n)大致成比例的时间.

  • Integer.toBinaryString(n) produces a string of length ceiling(log2(n)). That computation will take time that is roughly proportional to log(n).

n的最大值为2 ^ 31-1,并且该计算将始终少于某个固定的恒定时间.

The maximum value for n is 2^31 - 1, and that computation will always take less than some fixed constant time.

实际上,Integer.toBinaryString(n)的O复杂性大的问题在数学上没有意义.根据定义,大的O复杂度与函数的行为有关,因为某些变量趋于无穷大.在这种情况下,唯一的变量(n)无法做到这一点.

In fact, the question of the big O complexity of Integer.toBinaryString(n) is not mathematically meaningful. By definition, big O complexity is about a function's behavior as some variable tends to infinity. And the only variable ( n ) cannot do that in this context.

这篇关于Java中Integer.toBinaryString()的时间复杂度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆