DS-chapter4(Splay Tree,B tree)

DS-chapter4(Splay Tree,B tree) - 4.5 Splay Trees Target Any...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
4.5 Splay Trees Target : Any M consecutive tree operations starting from an empty tree take at most O( M log N ) time. Does it mean that every operation takes O(log N ) time? No. It means that the amortized time is O(log N ). So a single operation might still take O( N ) time? Then what’s the point? The bound is weaker. But the effect is the same: There are no bad input sequences. But if one node takes O( N ) time to access, we can keep accessing it for M times, can’t we? Sure we can – that only means that whenever a node is accessed, it must be moved . Idea : After a node is accessed, it is pushed to the root by a series of AVL tree rotations.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
k 5 F k 4 E k 3 D k 2 A k 1 C B Splay Trees k 5 F k 4 E k 3 D k 2 B A k 1 C k 5 F k 4 E k 2 B A k 1 k 3 D C k 5 F k 4 E k 2 B A k 1 k 3 D C k 4 E k 5 F k 2 B A k 1 k 3 D C Does NOT work!
Background image of page 2
Splay Trees An even worse case: 1 2 2 1 3 3 2 1 Insert : 1, 2, 3, … N 3 2 1 N Find : 1 3 2 1 N Find : 2 3 1 2 N …… Find : N 3 2 1 N T ( N ) = O ( N 2 )
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
§5 Splay Trees Try again -- For any nonroot node X
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 11

DS-chapter4(Splay Tree,B tree) - 4.5 Splay Trees Target Any...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online