k: 5

17
K: 5 P: 9 K: 1 P: 2 P: 6 K: 8 K: 7 P: 4

Upload: mollie-rhodes

Post on 01-Jan-2016

22 views

Category:

Documents


0 download

DESCRIPTION

K: 5. P: 9. K:1. K: 8. P:2. P: 6. K: 7. P: 4. K: 5. P: 9. K:1. K: 8. P:2. P: 6. Is the treap a heap?. K: 7. P: 4. P: 9. P:2. P: 6. For every node v, the search key in v is greater than or equal to those in the children of v. P: 4. K: 5. P: 9. K:1. K: 8. P:2. P: 6. - PowerPoint PPT Presentation

TRANSCRIPT

K: 5

P: 9

K:1P:2

P: 6

K: 8

K: 7

P: 4

K: 5

P: 9

K:1P:2

P: 6

K: 8

K: 7

P: 4

Is the treap a heap?

P: 9

P:2P: 6

P: 4

For every node v, the search key in v is greater than or equal to those in the children of v

K: 5

P: 9

K:1P:2

P: 6

K: 8

K: 7

P: 4

Not a complete tree! NO!

K: 5

P: 9

K:1P:2

P: 6

K: 8

K: 7

P: 4

Is the treap a Binary Search Tree?

K: 5

K:1 K: 8

K: 7BST? Yes!

K: 5

K:1 K: 8

K: 7

All keys smaller than the root are stored in the left subtree

All keys larger than the root are sorted in the right subtree

(K, P)(5,9)(7,4)(8,6)(1,2)

K: 5

P: 9K:1P:2 P: 6

K: 8K: 7

P: 4

(K, P)(5,9)(7,4)(8,6)(1,2)

K: 5

P: 9

K:1P:2

P: 6

K: 8

K: 7

P: 4

K: 5

P: 9

K:1P:2

P: 6

K: 8

K: 7

P: 4

K: 5

P: 9

K:1P:2

P: 6

K: 8

K: 7

P: 4

K: 5

P: 9

K:1P:2

P: 6

K: 8

K: 7

P: 4

Assume no duplicate key / priority, only one treap is possible

(2,5) (5,2) (3,1) (4,7) (9,4) (8,3)

K:2P:5

K:5P:2

K:3P:1

K:4P:7

K:9P:4

K:8P:3

K:2P:5

K:5P:2

K:3P:1

K:4P:7

K:9P:4

K:8P:3

Arrange from left to right,

Smallest key Biggest key

K:2P:5

K:5P:2

K:3P:1

K:4P:7

K:9P:4

K:8P:3

Without destroying left to right arrangement,Shift the “nodes” up and down

Biggest priority

Smallest priority

K:2P:5

K:5P:2K:3

P:1

K:4P:7

K:9P:4

K:8P:3

K:2P:5

K:5P:2

K:3P:1

K:4P:7

K:9P:4

K:8P:3