minimum_depth_binary tree

本文介绍了一种使用递归方法寻找二叉树最小深度的算法实现。通过对根节点及其左右子树进行递归调用,计算从根节点到最近叶子节点的最短路径长度。

题目描述:
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

思路:

用递归的思想:

如果根结点为空,就返回0;

如果左子树为空,就返回右子树的最小深度+1(算上根结点这一层)

如果右子树为空,就返回左子树的最小深度+1

如果左、右子树都不为空,则返回左、右子树最小深度+1

class solution{
public:
    int run(TreeNode *pRoot)
    {
        if(pRoot == NULL){     //根结点为空,返回0值
            return 0;
        }
        if(pRoot->pLeft == NULL){     //左子树为空,返回右子树的最小深度+1;
            return run(pRoot->Pright)+1;
        }
        if(pRoot->pright == NULL){    //右子树为空,返回左子树的最小深度+1;
            return run(pRoot->pLeft);
        }
        //左右子树都不为空,返回左右子树中的最小深度+1
        int LeftDepth = run(pRoot->pLeft)+1; 
        int RightDepth = run(pRoot->pRight)+1;
        return (LeftDepth < RightDepth)?(LeftDepth+1):(RightDepth+1);
    }
};

 

内容概要:本文系统阐述了智能物流路径规划的技术体系与实践应用,涵盖其发展背景、核心问题建模、关键算法、多目标与动态环境处理、系统架构及典型应用场景。文章以车辆路径问题(VRP)及其变体为核心数学模型,介绍了从Dijkstra、A*等单智能体算法到多车VRP的元启发式求解方法(如遗传算法、蚁群算法、大规模邻域搜索),并深入探讨了多目标优化(成本、时间、碳排放)与动态环境(实时订单、交通变化)下的自适应规划策略。结合城市配送、干线运输、场内物流等案例,展示了路径规划在提升效率、降低成本方面的实际价值,并分析了当前面临的复杂性、不确定性等挑战,展望了AI融合、数字孪生、车路协同等未来趋势。; 适合人群:具备一定物流、运筹学或计算机基础,从事智能交通、物流调度、算法研发等相关工作的技术人员与管理人员,工作年限1-5年为宜。; 使用场景及目标:①理解智能物流路径规划的整体技术架构与核心算法原理;②掌握VRP建模方法与多目标、动态环境下路径优化的实现策略;③为物流系统设计、算法选型与系统优化提供理论依据与实践参考; 阅读建议:建议结合文中案例与数学模型,重点理解算法选择与实际业务场景的匹配逻辑,关注动态规划与多目标优化的工程实现难点,可配合仿真工具或开源求解器进行实践验证。
nsert 2, 1, 4, 5, 9, 3, 6, 7 into an initially empty AVL tree. Which one of the following statements is FALSE? A. 4 is the root B. 3 and 7 are siblings C. 2 and 6 are siblings D. 9 is the parent of 7 分数 3 作者 陈越 单位 浙江大学 如果AVL树的深度为5(空树的深度定义为0),则此树最少有多少个结点? A. 12 B. 20 C. 33 D. 64 分数 2 作者 徐镜春 单位 浙江大学 将 7, 8, 9, 2, 3, 5, 6, 4 顺序插入一棵初始为空的AVL树。下列句子中哪句是错的? A. 7 是根结点 B. 2 和 5 是兄弟 C. 有2个结点的平衡因子为-1 D. 3 是 4 的父结点 分数 2 作者 何钦铭 单位 浙江大学 For an AVL-tree of height 4, what is the minimum number of the tree nodes? (the height of one node tree is 0) A. 11 B. 12 C. 14 D. 15 分数 2 作者 何钦铭 单位 浙江大学 During inserting { 42, 26, 8, 70, 102, 56, 2} into an initially empty AVL tree, which of the following statements is true? A. The resulted AVL tree is also a completed binary tree; B. There are 4 rotations: LL,RR,LR,LL C. There are 4 rotations: LL,RR,LL,RL D. There are 3 rotations: LL,RR,RL 分数 2 作者 何钦铭 单位 浙江大学 When inserting 1, 2, 3, 6, 5, and 4 one by one into an initially empty AVL tree,which kinds of rotations will be encountered? A. Two RR's and one RL B. One RR, one RL, and one LR C. One RR and two RL's D. Two RR's and one LR 分数 2 作者 陈越 单位 浙江大学 将 26, 13, 44, 51, 98, 37, 66, 73 顺序插入一棵初始为空的AVL树。下列句子中哪句是错的? A. 44 是根结点 B. 37 和 73 是兄弟 C. 26 和 66 是兄弟 D. 26 是 13 的父结点 分数 2 作者 何钦铭 单位 浙江大学 将一系列数字顺序一个个插入一棵初始为空的AVL树。下面哪个系列的第一次旋转是“右-左”双旋? A. 1,2,3,4,5,6 B. 6,5,4,3,2,1 C. 4,2,5,6,3,1 D. 3,1,4,6,5,2 分数 2 作者 考研真题 单位 浙江大学 Delete a node v from an AVL tree T1​, we can obtain another AVL tree T2​. Then insert v into T2​, we can obtain another AVL tree T3​. Which one(s) of the following statements about T1​ and T3​ is(are) true? I、If v is a leaf node in T1​, then T1​ and T3​ might be different. II、If v is not a leaf node in T1​, then T1​ and T3​ must be different. III、If v is not a leaf node in T1​, then T1​ and T3​ must be the same. A. I only B. II only C. I and II only D. I and III only 分数 2 作者 何钦铭 单位 浙江大学 Insert 28, 23, 54, 61, 98, 37 into an initially empty AVL tree first. Then immediately insert one of the following keys. Which one will cause an RL rotation? A. 10 B. 30 C. 60 D. 70 分数 2 作者 何钦铭 单位 浙江大学 Insert 28, 23, 54, 61, 98, 37 into an initially empty AVL tree first. Then immediately insert one of the following keys. Which one will cause an RL rotation? A. 10 B. 50 C. 80 D. 100 分数 3 作者 陈越 单位 浙江大学 If there are 14 nodes in an AVL tree, then the maximum depth of the tree is ____. The depth of an empty tree is defined to be 0. A. 3 B. 4 C. 5 D. 6 分数 3 作者 陈越 单位 浙江大学 If there are 28 nodes in an AVL tree, then the maximum depth of the tree is ____. The depth of an empty tree is defined to be -1. A. 3 B. 4 C. 5 D. 6 分数 3 作者 DS课程组 单位 浙江大学 If the depth of an AVL tree is 6 (the depth of an empty tree is defined to be -1), then the minimum possible number of nodes in this tree is: A. 13 B. 17 C. 20 D. 33 分数 2 作者 101 数据结构团队 单位 101计划 给定关键词输入序列 { CAP, AQU, PIS, ARI, TAU, GEM, CAN, LTB, VIR, LEO, SCO },,试按表中元素的次序,依次插入一棵初始为空的 AVL 树(字符之间以字典顺序比较大小)。则关于最后产生的 AVL 树,哪句描述是错误的? A. 在形成结果树的过程中,涉及 2 次旋转调整 B. LTB 是 GEM 的父结点 C. PIS 是 TAU 的父结点 D. CAP 是根结点
10-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值