当前位置:网站首页>在最长的距离二叉树结点
在最长的距离二叉树结点
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
边栏推荐
- Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
- PG basics -- Logical Structure Management (transaction)
- ACdreamoj1110(多重背包)
- 3D人脸重建:从基础知识到识别/重建方法!
- El table table - sortable sorting & disordered sorting when decimal and% appear
- R language visualizes the relationship between more than two classification (category) variables, uses mosaic function in VCD package to create mosaic plots, and visualizes the relationship between tw
- OSPF多区域配置
- Start the embedded room: system startup with limited resources
- HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
- 通过数字电视通过宽带网络取代互联网电视机顶盒应用
猜你喜欢

PHP saves session data to MySQL database

966 minimum path sum

The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop
![[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics](/img/2d/9a7e88fb774984d061538e3ad4a96b.png)
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics

Study notes of grain Mall - phase I: Project Introduction

Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?

HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅

Common English vocabulary that every programmer must master (recommended Collection)

Deployment of external server area and dual machine hot standby of firewall Foundation

嵌入式开发的7大原罪
随机推荐
Yyds dry inventory run kubeedge official example_ Counter demo counter
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
ICML 2022 | flowformer: task generic linear complexity transformer
js通过数组内容来获取数组下标
What is the problem with the SQL group by statement
Three schemes of SVM to realize multi classification
Select data Column subset in table R [duplicate] - select subset of columns in data table R [duplicate]
Opencv learning example code 3.2.3 image binarization
OneNote in-depth evaluation: using resources, plug-ins, templates
愛可可AI前沿推介(7.6)
20220211 failure - maximum amount of data supported by mongodb
JS traversal array and string
js之遍历数组、字符串
Deployment of external server area and dual machine hot standby of firewall Foundation
ACdreamoj1110(多重背包)
【深度学习】PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
【mysql】触发器
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
【论文解读】用于白内障分级/分类的机器学习技术
Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices