当前位置:网站首页>在最长的距离二叉树结点
在最长的距离二叉树结点
2022-07-06 12:57:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
分为两:①当后最长的距离root
②没有距离最长root,
1. 若路径经过根Root。则U和V是属于不同子树的,且它们都是该子树中道根节点最远的节点。否则跟它们的距离最远相矛盾。这样的情况如图3-13所看到的:
2. 假设路径不经过Root。那么它们一定属于根的K个子树之中的一个。
而且它们也是该子树中相距最远的两个顶点。如图3-14中的节点A:
设第K棵子树中相距最远的两个节点:Uk和Vk,其距离定义为d(Uk,Vk),那么节点Uk或Vk即为子树K到根节点Rk距离最长的节点。不失一般性。我们设Uk为子树K中道根节点Rk距离最长的节点。其到根节点的距离定义为d(Uk,R)。取d(Ui,R)(1<=i<=k)中最大的两个值max1和max2。那么经过根节点R的最长路径为max1+max2+2,所以树R中相距最远的两个点的距离为:max{d(U1,V1),…, d(Uk,Vk),max1+max2+2}。
採用深度优先搜索如图3-15,仅仅须要遍历全部的节点一次,时间复杂度为O(|E|)=O(|V|-1),当中V为点的集合。E为边的集合。
版权声明:本文博主原创文章。博客,未经同意不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/117115.html原文链接:https://javaforall.cn
边栏推荐
- Vim 基本配置和经常使用的命令
- What is the problem with the SQL group by statement
- 华为设备命令
- Web开发小妙招:巧用ThreadLocal规避层层传值
- Performance test process and plan
- OSPF多区域配置
- Nodejs tutorial expressjs article quick start
- JS get array subscript through array content
- Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
- What's the best way to get TFS to output each project to its own directory?
猜你喜欢

KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning

20220211 failure - maximum amount of data supported by mongodb

基于STM32单片机设计的红外测温仪(带人脸检测)

Opencv learning example code 3.2.3 image binarization

防火墙基础之外网服务器区部署和双机热备

967- letter combination of telephone number

愛可可AI前沿推介(7.6)

每个程序员必须掌握的常用英语词汇(建议收藏)

性能测试过程和计划

Performance test process and plan
随机推荐
全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
Comprehensive evaluation and recommendation of the most comprehensive knowledge base management tools in the whole network: flowus, baklib, jiandaoyun, ones wiki, pingcode, seed, mebox, Yifang cloud,
Nodejs教程之Expressjs一篇文章快速入门
Infrared thermometer based on STM32 single chip microcomputer (with face detection)
面试官:Redis中有序集合的内部实现方式是什么?
This year, Jianzhi Tencent
Opencv learning example code 3.2.3 image binarization
通过数字电视通过宽带网络取代互联网电视机顶盒应用
什么是RDB和AOF
What is the difference between procedural SQL and C language in defining variables
document.write()的用法-写入文本——修改样式、位置控制
OneNote 深度评测:使用资源、插件、模版
基于深度学习的参考帧生成
b站视频链接快速获取
None of the strongest kings in the monitoring industry!
Is this the feeling of being spoiled by bytes?
Aiko ai Frontier promotion (7.6)
嵌入式开发的7大原罪
js中,字符串和数组互转(一)——字符串转为数组的方法
What is the problem with the SQL group by statement