1 / 17

K: 5

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.

Download Presentation

K: 5

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. K: 5 P: 9 K:1 K: 8 P:2 P: 6 Is the treap a heap? K: 7 P: 4

  3. 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

  4. K: 5 P: 9 K:1 K: 8 P:2 P: 6 Not a complete tree! NO! K: 7 P: 4

  5. K: 5 P: 9 K:1 K: 8 P:2 P: 6 Is the treap a Binary Search Tree? K: 7 P: 4

  6. K: 5 K:1 K: 8 BST? Yes! K: 7

  7. K: 5 K:1 K: 8 All keys smaller than the root are stored in the left subtreeAll keys larger than the root are sorted in the right subtree K: 7

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

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

  10. K: 5 P: 9 K: 8 P: 6 K: 7 P: 4 K:1 P:2

  11. K: 5 P: 9 K: 8 P: 6 K: 7 P: 4 K:1 P:2

  12. K: 5 P: 9 K:1 K: 8 P:2 P: 6 Assume no duplicate key / priority, only one treap is possible K: 7 P: 4

  13. (2,5) (5,2) (3,1) (4,7) (9,4) (8,3) K:2 K:5 K:3 K:4 K:9 K:8 P:5 P:2 P:1 P:7 P:4 P:3

  14. Arrange from left to right, Smallest key Biggest key K:8 K:9 K:4 K:5 K:2 K:3 P:3 P:4 P:7 P:2 P:5 P:1

  15. K:4 P:7 K:2 Without destroying left to right arrangement, Shift the “nodes” up and down P:5 K:9 P:4 Biggest priority K:8 P:3 Smallest priority K:5 P:2 K:3 P:1

  16. K:4 P:7 K:2 P:5 K:9 P:4 K:8 P:3 K:5 P:2 K:3 P:1

  17. K:4 P:7 K:9 K:2 P:4 P:5 K:8 K:3 P:3 P:1 K:5 P:2

More Related