二叉树的详细分类与应用场景(Java代码实现)

二叉树的详细分类与应用场景(Java代码实现)

2023年6月22日发(作者:)

⼆叉树的详细分类与应⽤场景(Java代码实现)1.⼆叉搜索树(Binary Search Tree)leetcode450.删除BST的结点class Solution { public TreeNode deleteNode(TreeNode root, int key) { if (root == null) return null; if (key < ) { = deleteNode(, key); return root; }//删除的节点在左⼦树中 if (key > ) { = deleteNode(, key); return root; }//删除的节点在右⼦树中 assert key == ; if ( == null) return ; if ( == null) return ; TreeNode predecessor = maximum(); TreeNode predecessorCopy = new TreeNode(); = removeMax(); = ; = = null; return predecessorCopy; } private TreeNode removeMax(TreeNode node) { if ( == null) return ; = removeMax(); return node; } private TreeNode maximum(TreeNode node) { if ( == null) return node; return maximum(); }}2.⼆叉平衡树(Adelson-Velskiitree)在⼆叉搜索树的插⼊和删除运算中,采⽤平衡树的优点是:使树的结构较好,从⽽提⾼查找运算的速度。缺点是:是插⼊和删除运算变得复杂化,从⽽降低了他们的运算速度。对⼆叉搜索树删除节点⽽引起的不平衡性进⾏的操作⽐插⼊节点的情况要复杂。

发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1687384377a6046.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信