cs212: data structures
DESCRIPTION
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. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/1.jpg)
CS212: DATA STRUCTURES
Trees Exercise Computer Science
Department
![Page 2: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/2.jpg)
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?
![Page 3: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/3.jpg)
Trees, Binary Trees, and Binary Search Trees
What is the path length of the path from node 20 to node 12? 3
![Page 4: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/4.jpg)
Trees, Binary Trees, and Binary Search Trees
What is the height of the tree?
![Page 5: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/5.jpg)
Trees, Binary Trees, and Binary Search Trees
What is the height of the tree? 4
![Page 6: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/6.jpg)
Trees, Binary Trees, and Binary Search Trees
Show what would this tree look like after: Adding 18
![Page 7: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/7.jpg)
Trees, Binary Trees, and Binary Search Trees
Show what would this tree look like after: Adding 18
18
18>16
18<20
![Page 8: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/8.jpg)
Trees, Binary Trees, and Binary Search Trees
Show what would this tree look like after: Delete 35
18
![Page 9: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/9.jpg)
Trees, Binary Trees, and Binary Search Trees
Show what would this tree look like after: Delete 35
18
![Page 10: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/10.jpg)
Trees, Binary Trees, and Binary Search Trees
Show what would this tree look like after: Delete 16
18
![Page 11: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/11.jpg)
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) .
18
12
![Page 12: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/12.jpg)
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
![Page 13: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/13.jpg)
Trees, Binary Trees, and Binary Search Trees
Show what would this tree look like after: Delete 20
18
![Page 14: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/14.jpg)
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
![Page 15: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/15.jpg)
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) .
![Page 16: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/16.jpg)
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:
![Page 17: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/17.jpg)
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
![Page 18: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/18.jpg)
AVL Tree
EX3: test if tree is AVL tree or not, if not convert it to AVL tree.
20
10
5
1
30
![Page 19: Cs212: Data Structures](https://reader033.vdocument.in/reader033/viewer/2022051418/5681576c550346895dc50fd9/html5/thumbnails/19.jpg)
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
10
5
1
30
EH
LH
LH
LH
EH
Out of balance
20
5 30
1
EH
EH
EH
EH
LH
Left to left imbalance case
AVL tree
10