当前位置:网站首页>Is the height of binary tree [log2n]+1 equal to log2 (n+1)
Is the height of binary tree [log2n]+1 equal to log2 (n+1)
2022-07-23 22:58:00 【quxuexi】
and
Whether it is equal or not ?
For integers , The two are equal ; For floating point numbers , The two are not necessarily equal .
Test code :
#include <stdio.h>
#include <math.h>
int main()
{
long int maxnum = 100000;
// Integer test
for(int n = 1; n<maxnum; n++)
{
int down = floor(log(n)/log(2)) + 1;
int up = ceil(log(n+1)/log(2));
if(down != up)
printf("down = %d,up = %d,n = %f\n",down,up,n);
}
printf("1 To %lu All integers between satisfy the equality of two formulas \n",maxnum);
// Floating point test
for(double n = 1; n<maxnum; n+=0.11)
{
int down = floor(log(n)/log(2)) + 1;
int up = ceil(log(n+1)/log(2));
if(down != up)
printf("down = %d,up = %d,n = %f\n",down,up,n);
}
double d = 3.0;
int b = floor(log(3.0)/log(2.0)) + 1;
int e = ceil(log(3.0+1)/log(2.0));
printf("\nb = %d,e = %d",b,e);
double p = log(3.000001+1);
double q = log(2);
int out = ceil(p/q);
printf("\np = %f,q = %f,out = %d",p,q,out);
return 0;
}
For the convenience of screenshots , Set the maximum value of the test to 30, Readers can set a larger value to test , The result should be the same

attach :
边栏推荐
- Memory search - DP
- Programming in the novel [serial 19] the moon bends in the yuan universe
- 狂神redis笔记10
- VIM common shortcut keys
- Rails with OSS best practices
- EasyNVR平台如何关闭匿名登录?
- Array -- 27. remove elements
- STM32F4查看系统各部分频率
- 【Matplotlib绘图】
- Programming in the novel [serial 18] the moon bends in the yuan universe
猜你喜欢

Extract any page number in PDF file with itextpdf

The ultimate experiment of OSPF -- learn the example of OSPF century template

STM32 MCU uses ADC function to drive finger heartbeat detection module

Getting started database days2

浅析基于NVR技术的视频能力与未来发展趋势

What else do entrepreneurs need besides money? Exclusive interview with Mingyue Lake venture capital institutions

Excel password related

海外资深玩家的投资建议(2) 2021-05-03
![Use of [golang learning notes] package](/img/be/71cb066f44ce4bdab13c79c2da2652.png)
Use of [golang learning notes] package

Still worrying about xshell cracking, try tabby
随机推荐
Array - 977. Square of ordered array
Preparation for raspberry pie 3B serial port login
D1-H 开发板——哪吒 开发入门
Debian | Can’t locate Debian/Debhelper/Sequence/germinate. pm in @INC
使用itextpdf提取PDF文件中的任意页码
砺夏行动 2022|源启数字化圆桌论坛即将上线
Lixia action 2022 Yuanqi digital round table forum will be launched soon
海外资深玩家的投资建议(2) 2021-05-03
狂神redis笔记10
unity visual studio2019升级到2022版本(扔掉盗版红渣)
Microsoft SQL Server database language and function usage (XIII)
Is Ping An Securities' low commission account opening link safe? How to handle low commission
Life always needs a little passion
Diabetes genetic risk testing challenge advanced
Inspiration from Buffett's shareholders' meeting 2021-05-06
Programming in the novel [serial 17] the moon bends in the yuan universe
疯狂的牛市,下半场何去何从?2021-04-30
Programming in the novel [serial 19] the moon bends in the yuan universe
Array - 11. Containers with the most water
synthesizable之Verilog可不可综合
and
Whether it is equal or not ?