Binary search tree

Tree:

  1. nodes
  2. two nodes only be connected by one path

Binary Tree:
3. the nodes have only 0,1,2

Binary search Tree
Every key in the left subtree is less than X’s key.
Every key in the right subtree is greater than X’s key. **Remember this property!! We will reference it a lot throughout the duration of this module and 61B.

Static method指用属于class的method,不需要object,所以只会运行一次。
而non-static method是针对于object,每次实例化一个object都会运行一次non-static method

static method只能引用static variable :
Static methods cannot access or change the values of instance variables or the this reference (since there is no calling object for them), and static methods cannot call non-static methods.

Worst-cases is more restrictive than bigO

depth: the number of links between a node and the root.
height: the lowest depth of a tree.
height: worst-case
average depth: average-case runtime

in B tree: the limit of numbers that a single node can contains is called L. B-trees of order L = 2 are also called a 2-3 tree.

if L =3, are called 2-3-4 tree.

log3 N, log2 N 都属于O(log N)

contains method and add method are both O(log N)

rotateRight(G) : find the left child of G called x, then make G be the new right child of X

向右rotate的话是先找node的左边的child node called x, 然后再将G和左边的child node x合并在一起,然后将G变成x的rightchild node,最后分配G 和 X 下面的child node,确保子child node 没有超过2个。

rotateLeft(G) : find the right child of G called x, then make G be the new left child of X

映射(reflection) A的任意元素,都有唯一的B中元素与之对应。

Binary search tree’s height is very dramatic. if the tree is bushy, the height will be bigTheta(log(N)). If the tree is spindly, the height will be bigTheta(N)

BigTheta is more informative than Big O in general:
for example:
The most expensive room in the hotel is 639 per night.
every room in the hotel is less than or equal to 639 per night
The first one shows the information, most expensive romm is 639,and all the rooms are equal or less than 639. This means the first statement includes the second information and also specify the most expensive room price information.

Big O is not mathematically the same thing as “worst case”
but big O often used as shorthand for “worst case”.

在这里插入图片描述

Right red links are not allowed in LLRB(left-leaning Red black binary search tree)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值