搜索树Search Tree

Search Tree

  如果比喻作人,AVL树就如同那种时时刻刻小心翼翼且谨慎的类型。这一节,我们寻找一种更为宽松的准则,让我们变成潇洒的人。下面介绍这节的猪脚伸展树。

  

 逐层伸展: 使得v的高度逐层上升:

实例:节点上升的过程是一个不断伸展,左右摇摆的过程。

一步一步往上爬这种策略,显然比较低效。哎 蜗牛好惨啊!!

 分析下最坏情况:




来看看点睛之笔:单层伸展变成双层伸展

  

 第一只眼睛:

  

 第二只眼睛:

 

 感受点睛之笔的魅力:

  调整一次之后,整棵树的树高有了本质的变化:每调整一次,树的高度竟然可以缩减一半,很快的就能变成平衡的状态,哇塞!!!

 

原文地址:https://www.cnblogs.com/ccpang/p/11565986.html

时间: 2024-10-25 22:31:32

搜索树Search Tree的相关文章

编程算法 - 二叉搜索树(binary search tree) 代码(C)

二叉搜索树(binary search tree) 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 二叉搜索树(binary search tree)能够高效的进行插入, 查询, 删除某个元素, 时间复杂度O(logn). 简单的实现方法例如以下. 代码: /* * main.cpp * * Created on: 2014.7.20 * Author: spike */ /*eclipse cdt, gcc 4.8.1*/ #include <s

235. Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的LCA

Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: "The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has

[LeetCode] Validate Binary Search Tree 验证二叉搜索树

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys

LeetCode 501. Find Mode in Binary Search Tree (找到二叉搜索树的众数)

Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than or equal to the nod

二叉排序树BinarySortTree(二叉搜索树Binary Search Tree)

二叉排序树(Binary Sort Tree)又称二叉查找树(Binary Search Tree),亦称二叉搜索树. 定义: 二叉排序树或者是一棵空树,或者是具有下列性质的二叉树: (1)若左子树不空,则左子树上所有结点的值均小于它的根结点的值: (2)若右子树不空,则右子树上所有结点的值均大于或等于它的根结点的值: (3)左.右子树也分别为二叉排序树: (4)没有键值相等的节点 步骤: 二叉树 若根结点的关键字值等于查找的关键字则成功. 否则,若小于根结点的关键字值,递归查左子树. 若大于根

[CareerCup] 4.3 Create Minimal Binary Search Tree 创建最小二叉搜索树

4.3 Given a sorted (increasing order) array with unique integer elements, write an algorithm to create a binary search tree with minimal height. 这道题给了我们一个有序的数组,让我们来生成一个最小高度的二叉搜索树,为了达到最小高度,肯定是尽可能的填成一个满二叉树,左子树填满,右子树尽可能的填满.而且要注意是二叉搜索树,左<根<右的性质不能忘.既然给了我

[LeetCode] Convert Sorted List to Binary Search Tree 将有序链表转为二叉搜索树

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 这道题是要求把有序链表转为二叉搜索树,和之前那道Convert Sorted Array to Binary Search Tree 将有序数组转为二叉搜索树思路完全一样,只不过是操作的数据类型有所差别,一个是数组,一个是链表.数组方便就方便在可以通过index直接访问任意一个元

[CareerCup] 4.5 Validate Binary Search Tree 验证二叉搜索树

4.5 Implement a function to check if a binary tree is a binary search tree. LeetCode上的原理,请参见我之前的博客Validate Binary Search Tree 验证二叉搜索树.

[LeetCode] Binary Search Tree Iterator 二叉搜索树迭代器

Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the next smallest number in the BST. Note: next() and hasNext() should run in average O(1) time and uses