当前位置:网站首页>在最长的距离二叉树结点
在最长的距离二叉树结点
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
边栏推荐
- Common English vocabulary that every programmer must master (recommended Collection)
- Performance test process and plan
- MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
- Forward maximum matching method
- Aike AI frontier promotion (7.6)
- Three schemes of SVM to realize multi classification
- 快过年了,心也懒了
- Ravendb starts -- document metadata
- 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,
- js中,字符串和数组互转(二)——数组转为字符串的方法
猜你喜欢
Interviewer: what is the internal implementation of ordered collection in redis?
966 minimum path sum
嵌入式开发的7大原罪
Reinforcement learning - learning notes 5 | alphago
2022 fields Award Announced! The first Korean Xu Long'er was on the list, and four post-80s women won the prize. Ukrainian female mathematicians became the only two women to win the prize in history
拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效
KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
No Yum source to install SPuG monitoring
随机推荐
Pat 1078 hashing (25 points) ⼆ times ⽅ exploration method
【深度学习】PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
967- letter combination of telephone number
Yyds dry goods count re comb this of arrow function
Vim 基本配置和经常使用的命令
如何实现常见框架
Thinking about agile development
硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
El table table - get the row and column you click & the sort of El table and sort change, El table column and sort method & clear sort clearsort
[MySQL] basic use of cursor
KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
Common English vocabulary that every programmer must master (recommended Collection)
Aiko ai Frontier promotion (7.6)
启动嵌入式间:资源有限的系统启动
SAP Fiori应用索引大全工具和 SAP Fiori Tools 的使用介绍
性能测试过程和计划
Word bag model and TF-IDF
Forward maximum matching method
Laravel notes - add the function of locking accounts after 5 login failures in user-defined login (improve system security)
对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事