

































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


































LECTURE 09: BINARY TREES, HEAPS, BINARY SEARCH TREES
2
S L R
5 17 9 15 6 5 8 Root node Left subtree Right child Left child
7 17 9 15 6 5 8 (^13 ) 23
8 17 9 15 6 5 8 13 42 23 (^7 3 1 31 96 )
Solution: BT Traversals - Print 11 Process Node Traverse Left Traverse Right public String asIndentedPreOrder(int indent) { String out = createPadding(indent) + getKey(); if (getLeft() != null) { out +="\n" + getLeft().asIndentedPreOrder(indent + 2); } if (getRight() != null) { out +="\n" + getRight().asIndentedPreOrder(indent + 2); } return out; }
20 17 9 15 (^6 5 8 ) Satisfy heap property Promote while element > parent 25