10-24 notes - Ordered Collections Insert Find Remove Min()...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Ordered Collections Insert Find Remove Min() – minimum key in collection Max() – maximum key in collection Pred(x) Succ(x) – record with next longest key after x.key Binary Trees Parent Left Right Binary Search Tree Property: Let x, y be nodes in a binary tree If y is in x’s left subtree, o y.key <= x.key If y is in x’s right subtree o Y.key >= x.key Always insert @ leaf Minimum – always go to the left until u can’t go left anymore Max – same as min just go right Worst case o Θ(h) o h – tree height Successor o InOrder(x) If x!=null{ InOrder(x.left) Print x.key InOrder(x.right) } o Succ(x) If(x.right!=null) Return x.right.min() Else Y=x.parent While(y!=null and x=y.right){ o X=y
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
o Y = y.parent } } Remove (x) – hardest method (second edition CLR, not 3 rd edition CLR, either is okay, prof just likes his better) o 3 cases X has no children Just delete that value, simple
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

10-24 notes - Ordered Collections Insert Find Remove Min()...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online