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: else: |
LeftDescendant(N) |
if N.Left= null return N else: |
RightAncestor(N) |
if N.Key< N.Parent.Key return N.Parent else: |
RangeSearch(x,y,R) |
L←∅ while N.Key≤ y if N.Key≥
x: N ←Next(N) return L |
Insert(k,R) |
P ←Find(k,R) |
Delete(N) |
if N.Right=
null: else: \\ X.Left=
null |
RotateRight(X) |
P ←X
.Parent P.AppropriateChild← Y X.Parent← Y, Y.Right← X B.Parent← X, X.Left← B |