wavec022

binary trees notes

Feb 18th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. Binary Trees
  2.  
  3. root of the tree
  4. leaf nodes are at the bottom
  5.  
  6. invariant for binary tree-- can only have 0, 1, or 2 branches off of a thing
  7. each thing is the value and then two pointers
  8.  
  9. BinTree[+A]
  10. this means that the type is auto determined upon being given a value
  11.  
  12. sealed trait BinTree[+A]
  13. keeps people from adding other types or something
  14.  
  15. two kinds-- node and empty
  16.  
  17. height of item in binary tree-- longest path from the node to a leaf
  18. depth-- number of edges from root to node
  19.  
  20. =====
  21.  
  22. trees provide efficient insertion and searching
  23.  
  24. in order traversal -- left item right
  25. pre order traversal -- item left right
  26. post order traversal -- left right item
  27. breadth first traversal -- all the items n shit
  28.  
  29. =====
  30.  
  31. def smaller(tup:(Int,Int)): (Int,Int) = tup Match {
  32. case (a,b) =>
  33. if(a<b) (a,b)
  34. else if(a>b) (b,a)
  35. else (a,a)
  36.  
  37. case _ => (0,0)
  38. }
  39.  
  40. =====
  41.  
  42. Binary Search Tree-- left side is less than node, right side is greater
Add Comment
Please, Sign In to add comment