balanced search trees n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Balanced Search Trees PowerPoint Presentation
Download Presentation
Balanced Search Trees

Loading in 2 Seconds...

play fullscreen
1 / 22

Balanced Search Trees - PowerPoint PPT Presentation


  • 85 Views
  • Uploaded on

Balanced Search Trees. Problem: Efficiency of BST is related to tree’s height. search, insert and remove follow a path from root to desired location range in value for ceil(log (N+1)) to N What affects height of BST? sensitive to order of data in which you insert or delete items.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

Balanced Search Trees


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
balanced search trees
Balanced Search Trees
  • Problem: Efficiency of BST is related to tree’s height.
    • search, insert and remove follow a path from root to desired location
    • range in value for ceil(log (N+1)) to N
  • What affects height of BST?
    • sensitive to order of data in which you insert or delete items.
  • Solution: Maintain balance by using variation of BST.
splay trees
Splay Trees
  • Type of balanced binary search trees.
  • Search, insert, delete, and split have amortized complexity O(log n) & actual complexity O(n).
  • Actual and amortized complexity of join is O(1).
  • Priority queue and double-ended priority queue versions outperform heaps over a sequence of operations.
  • Two varieties.
    • Bottom up.
    • Top down.
top down splay trees
Top-Down Splay Trees
  • On the way down the tree, split the tree into the binary search trees S (smallelements)and B (bigelements).
    • Similar to split operation in an unbalanced binary search tree.
    • However, a rotation is done whenever an LL or RR move is made.
    • Move down 2 levels at a time, except (possibly) in the end when a one level move is made.
  • When the splay node is reached, S, B,and the subtree rooted at the splay node are combined into a single binary search tree.
two level moves

A

B

a

b

C

D

c

d

E

e

m

f

g

Two-Level Moves
  • RL move from A to C.
  • RR move from C to E.
  • L move from E to m.
  • Let m be the splay node.
rl move

S

B

A

B

a

b

C

D

c

d

E

e

m

f

g

RL Move
rl move1

S

B

C

D

c

d

E

e

m

f

g

RL Move

A

B

a

b

Same outcome as in split.

rr move

S

B

C

D

c

d

E

e

m

f

g

RR Move

A

B

a

b

rr move1

S

B

RR Move

A

B

a

D

b

C

E

c

d

e

m

Rotation performed.

f

g

Outcome is different from split.

l move

S

B

L Move

A

B

a

D

b

C

E

c

d

e

m

f

g

l move1

S

B

L Move

A

B

E

a

D

b

e

C

c

d

m

f

g

wrap up

S

B

Wrap Up

m

f

g

A

B

E

a

D

b

e

C

c

d

wrap up1

S

B

Wrap Up

m

A

B

E

a

D

b

g

e

C

f

c

d

wrap up2
Wrap Up

m

A

B

E

a

D

b

g

e

C

f

c

d

youtube lecture
YouTube lecture
  • CS 61B Lecture 34: Splay Trees
java applets
Java Applets
  • http://www.ibr.cs.tu-bs.de/courses/ss98/audii/applets/BST/SplayTree-Example.html
  • http://techunix.technion.ac.il/~itai/