1 / 19

Cs212: Data Structures

Cs212: Data Structures. Trees Exercise. Trees, Binary Trees, and Binary Search Trees. Answer the following questions for the tree shown below.  What is the path length of the path from node 20 to node 12?. Trees, Binary Trees, and Binary Search Trees.

sally
Télécharger la présentation

Cs212: Data Structures

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. Cs212: Data Structures Computer Science Department Trees Exercise

  2. Trees, Binary Trees, and Binary Search Trees • Answer the following questions for the tree shown below.  • What is the path length of the path from node 20 to node 12?

  3. Trees, Binary Trees, and Binary Search Trees  What is the path length of the path from node 20 to node 12? 3

  4. Trees, Binary Trees, and Binary Search Trees • What is the height of the tree?

  5. Trees, Binary Trees, and Binary Search Trees • What is the height of the tree? 4

  6. Trees, Binary Trees, and Binary Search Trees • Show what would this tree look like after: • Adding 18

  7. Trees, Binary Trees, and Binary Search Trees • Show what would this tree look like after: • Adding 18 18<20 18>16 18

  8. Trees, Binary Trees, and Binary Search Trees • Show what would this tree look like after: • Delete 35 18

  9. Trees, Binary Trees, and Binary Search Trees • Show what would this tree look like after: • Delete 35 18

  10. Trees, Binary Trees, and Binary Search Trees • Show what would this tree look like after: • Delete 16 18

  11. Trees, Binary Trees, and Binary Search Trees • Show what would this tree look like after: • Delete 16 , After delete node 16 we replace it by predecessor(largest node of left sub tree) . 12 18

  12. Trees, Binary Trees, and Binary Search Trees • Show what would this tree look like after: • Delete 16 , After delete node 16 we replace it by successor(smallest node of right sub tree) . 18

  13. Trees, Binary Trees, and Binary Search Trees • Show what would this tree look like after: • Delete 20 18

  14. Trees, Binary Trees, and Binary Search Trees • Show what would this tree look like after: • Delete 20, After delete node 20 we replace it by predecessor(largest node of left sub tree) . 18

  15. Trees, Binary Trees, and Binary Search Trees • Show what would this tree look like after: • Delete 20,After delete node 20 we replace it by successor(smallest node of right sub tree) .

  16. Trees, Binary Trees, and Binary Search Trees • EX2:Traverse the tree shown below in: • Preorder travers VLR: • In order travers LVR: • Post order travers LRV:

  17. Trees, Binary Trees, and Binary Search Trees • EX2:Traverse the tree shown below in: • Preorder travers VLR: • 20,16,11,10,12,43,35,48,45,65 • In order travers LVR: • 10,11,12,16,20,35,43,45,48,65. • Post order travers LRV: • 10,12,11,16,35,45,65,48,43,20

  18. AVL Tree • EX3: test if tree is AVL tree or not, if not convert it to AVL tree. 20 10 30 5 1

  19. AVL Tree • EX3: test if tree is AVL tree or not, if not convert it to AVL tree. Not AVL tree because node 10 out of balance. 20 20 Out of balance LH LH 10 30 5 30 LH EH EH EH 5 1 10 LH EH EH 1 Left to left imbalance case AVL tree EH

More Related