12.29 2-3-4树之总结
来源:互联网 发布:阿里云应用引擎 编辑:程序博客网 时间:2024/05/16 10:16
2-3-4树之总结
花了两天的时间终于搞定了这原以为会很容易的一个小程序--实现对一个2-3-4树的插入操作。之所以花这么长时间,主要原因是走了很多弯路,犯了一些常识性的错误,为了防止重犯此类错误,故作此小记,以加深印象。
首先,在开始写程序的时候就没搞清楚2-3-4树的概念,虽然也查了一些资料,但这种很抽象的东西还是有些难以理解,维基百科上实际上已经将2-3-4树的算法步写出来了,但我反复读了二三十遍才看明白。还是直接总结经验吧,条理分明些。
- 在框架还没有搭好之前,不要写细节代码。先用system.out.println()进行测试,测试成功了再开始具体实现。
- 在算法步骤没有彻底想明白之前,不要写任何一行代码。最好先画几张示意图,在图上通过了之后,再开始写。
- 不要改变传入函数的参数,否则就不要传引用进去
- 在写代码之前,先用自然语言将算法步描述出来,这些自然语句可以放入注释中。
- 程序的各个代码段之间的分工要明确。
顺便插入维基百科上对2-3-4树插入算法的描述:
To insert a value, we start at the root of the 2-3-4 tree:
- If the current node is a 4-node:
- Push the middle element of the 4-node up into the parent, leaving a 3-node.
- Split the remaining 3-node up into a pair of 2-nodes.
- If this is the root node (which thus has no parent), the middle value becomes the new root 2-node and the tree height increases by 1. Ascend into the root.
- Otherwise, push the middle value up into the parent node. Ascend into the parent node.
- Find the child whose interval contains the value to be inserted.
- If the child is empty, insert the value into current node and finish.
- Otherwise, descend into the child and repeat from step 1.
- 12.29 2-3-4树之总结
- 面试总结之-树
- 总结之树
- 数据结构总结之树
- 数据结构之排序总结4
- 树问题总结之哈夫曼树
- 树总结之并查集趣解
- 总结之线段树1
- 数据结构总结之线段树
- 数据结构总结之线段树
- 数据结构之排序总结3
- HMM学习3之总结
- 数据结构排序之总结2
- PE 学习之总结2
- python之函数总结2
- Xutils3总结2之数据库
- 数组之2Sum,3Sum,4Sum,3Sum closest总结
- 学习敏捷开发(trello)之party_bid卡片3,4总结
- c#时间变量进行比较
- 界面控件资源
- 使用Visual C++实现OLE剪贴板
- Coolite Toolkit Confirm弹出框!
- 禁止asp.net网页缓存
- 12.29 2-3-4树之总结
- ubuntu下apt-get 命令参数
- VB实现全窗体移动
- 不用spring,hibernate超傻瓜JAVA开发(javabean+数组)
- Android 3D view overlay on Camera view
- windos找不到文件:打开fla文件时候报错!
- foobar技巧两则
- CSDN报验证码错误
- Dreamweaver一句话技巧集萃