sorted sequence
We store the items in an arraybased sequence, sorted by key
We use an external comparator for the keys
Performance:
get
,
floorEntry
and
ceilingEntry
take
O
(log
n
)
time, using binary
search
get
takes
O
(
n
)
time since in the worst case we have to shift
n
/
2
items to make room for the new item
erase
take
O
(
n
)
time since in the worst case we have to shift
n
/
2
items to compact the items after the removal
The lookup table is effective only for dictionaries of small size or
for dictionaries on which searches are the most common
operations, while insertions and removals are rarely performed
(e.g., credit card authorizations)
© 2010 Goodrich, Tamassia
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
5
Binary Search Trees
A binary search tree is a
binary tree storing keys
(or keyvalue entries) at
its internal nodes and
satisfying the following
property:
Let
u
,
v
, and
w
be three
nodes such that
u
is in
the left subtree of
v
and
w
is in the right subtree
of
v
. We have
key
(
u
)
key
(
v
)
key
(
w
)
External nodes do not
store items
An inorder traversal of a
This is the end of the preview.
Sign up
to
access the rest of the document.
 Winter '09
 Binary Search, Binary search trees

Click to edit the document details