当前位置:网站首页>在最长的距离二叉树结点
在最长的距离二叉树结点
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
边栏推荐
- 【深度学习】PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
- 通过数字电视通过宽带网络取代互联网电视机顶盒应用
- JS操作dom元素(一)——获取DOM节点的六种方式
- 全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
- Aike AI frontier promotion (7.6)
- Common English vocabulary that every programmer must master (recommended Collection)
- document. Usage of write () - write text - modify style and position control
- Ravendb starts -- document metadata
- Mtcnn face detection
- 【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
猜你喜欢
Infrared thermometer based on STM32 single chip microcomputer (with face detection)
Common English vocabulary that every programmer must master (recommended Collection)
968 edit distance
MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
Deployment of external server area and dual machine hot standby of firewall Foundation
基于深度学习的参考帧生成
OAI 5g nr+usrp b210 installation and construction
Performance test process and plan
Study notes of grain Mall - phase I: Project Introduction
请问sql group by 语句问题
随机推荐
##无yum源安装spug监控
PHP saves session data to MySQL database
[interpretation of the paper] machine learning technology for Cataract Classification / classification
Swagger UI tutorial API document artifact
New database, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, Feishu multidimensional table, heipayun, Zhixin information, YuQue
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
代理和反向代理
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
After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
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,
Study notes of grain Mall - phase I: Project Introduction
Is it profitable to host an Olympic Games?
Thinking about agile development
[MySQL] basic use of cursor
KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
Huawei device command
愛可可AI前沿推介(7.6)
Reflection operation exercise
Mtcnn face detection
面试官:Redis中有序集合的内部实现方式是什么?