文档详情

数据结构解析.ppt

发布:2016-10-18约2.49万字共91页下载文档
文本预览下载声明
* All cost depth of the node in question. Worst case: ?(n). Average case: ?(log n). NEED TO REPEAT. * * * * * How to get a good number of exchanges? Induction leads to the following algorithm: Heapify the root’s subtrees, then push the root to the correct level. * How to get a good number of exchanges? Induction leads to the following algorithm: Heapify the root’s subtrees, then push the root to the correct level. * * * * * * (i-1) is number of steps down, n/2i is number of nodes at that level. * * current * current * * * C: 1110 D: 101 E: 0 F: 1111 K: 111101 L: 110 U: 100 Z: 111100 * * * C: 1110 D: 101 E: 0 F: 1111 K: 111101 L: 110 U: 100 Z: 111100 * These terms can be hard to distinguish. Students will need to remember which is which, since this notation will be used several times during the course. * This theorem is important, because it helps us to calculate space requirements. It tells us how many nodes are internal and how many are leaf. We need to know this if we have separate implementations for internal and leaf nodes * 最密集和平衡的状态 * Standard implementation (illustrating BinNodePtr class shown earlier). Leaf implementation is identical to internal node implementation, resulting in much wasted space due to null pointers. * * * * * * The first implementation is preferred. The second implementation illustrates a common programming style by many students. It attempts to “look ahead” at the node to be called to determine if it is null or not. This is highly error prone, because the calling function must make sure not to pass in a null pointer for the tree root. It might appear to be more efficient (since it does not make recursive calls on the empty pointers), but it is not in reality since it is checking the pointers twice (to see if not null, then to process them). * The first implementation is preferred. The second implementation illustrates a common programming style by many students. It attempts to “look ahead” at the node to be called to d
显示全部
相似文档