Binary Search Tree--Data Structure

Hash table

RangeSearch: impossible

NearestNeighbors: impossible

Insert:   O(1)

Delete:  O(1)


Array:

RangeSearch:        O(n)

NearestNeighbors: O(n)

Insert:                     O(1)

Delete:                    O(1)


Sorted Array:

RangeSearch:        O(logn)

NearestNeighbors: O(logn)

Insert:                     O(n)

Delete:                    O(n)


Linked List:

RangeSearch:        O(n)

NearestNeighbors: O(n)

Insert:                     O(1)

Delete:                    O(1)


Search Tree Property

X’s key is larger than the key of any descendent of its left child, and smaller than the key of any descendant of its right child.


Operations:

Find(k,R)

if R.Key= k:

  return R

else if R.Key> k:

  return Find(k,R.Left)

else if R.Key< k:

  return Find(k,R.Right)



Find (modified)

else if R.Key> k:

  if R.Left!=null:

    return Find(k,R.Left)

return R


Next(N)

if N.Right!=null:
  return LeftDescendant
(N.Right)

else:
  return RightAncestor
(N)


LeftDescendant(N)

if N.Left= null

  return N

else:
  return LeftDescendant
(N.Left)


RightAncestor(N)

if N.Key< N.Parent.Key

  return N.Parent

else:
  return RightAncestor
(N.Parent)



RangeSearch(x,y,R)

L←∅
N Find(x,R)

while N.Keyy

  if N.Keyx:
    L L.Append(N)

  N Next(N)

return L


Insert(k,R)

P Find(k,R)
Add new node with keyk as child  of P


Delete(N)

if N.Right= null:
  Remove
N, promoteN.Left

else:
  X Next(N)

\\   X.Left= null
  Replace N byX, promoteX.Right


RotateRight(X)

P X .Parent
Y X.Left
B Y .Right
Y .ParentP

P.AppropriateChildY

X.ParentYY.RightX

B.ParentXX.LeftB




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值