06 - Trees

1,384 views

Published on

I used this set of slides for the lecture on Trees I gave at the University of Zurich for the 1st year students following the course of Formale Grundlagen der Informatik.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,384
On SlideShare
0
From Embeds
0
Number of Embeds
17
Actions
Shares
0
Downloads
41
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

06 - Trees

  1. 1. Trees www.tudorgirba.com
  2. 2. n5 n2 n6 n10 n1 n7 n4 n9 n3 n8
  3. 3. n5 n2 n6 n10 n1 n7 n4 n9 n3 n8
  4. 4. n5 n2 n6 n10 n1 n7 n4 n9 n3 n8
  5. 5. n5 n2 n6 n10 n1 n7 n4 n9 n3 n8 edge node
  6. 6. n5 n2 n6 n10 n1 n7 n4 n9 n3 n8 leaf root
  7. 7. n5 n2 n6 n10 n1 n7 n4 n9 n3 n8 parent child
  8. 8. n5 n2 n6 n10 n1 n7 n4 n9 n3 n8 subtree
  9. 9. n5 n2 n6 n10 n1 n7 n4 n9 n3 n8 path
  10. 10. n5 n2 n6 n10 n1 n7 n4 n9 n3 n8 height = 1 depth = level = 2 degree = 1
  11. 11. n5 n2 n6 n10 n1 n7 n4 n9 n3 n8 height = 1 depth = level = 1 degree = 3
  12. 12. n5 n2 n6 n10 n1 n7 n4 n9 n3 n8 0 1 2 3
  13. 13. n5 n2 n6 n10 n1 n7 n4 n9 n3 n8 ordered tree leftmost rightmost
  14. 14. n5 n2 n6 n10 n1 n7 n4 n9 n3 n8 n7 n4 n9n8 n1 n5 n4 n6 n3 n10 isomorphic trees
  15. 15. n4 n2 n5 n1 n6 n3 n7 left right left leftright right
  16. 16. n4 n2 n5 n1 n3 n6 n4 n2 n5 n1 n6 n3 not a binary tree binary tree n4 n2 n5 n1 n6 n3 n7 complete binary tree
  17. 17. breadth-first traversal n4 n2 n5 n1 n6 n3
  18. 18. breadth-first traversal n4 n2 n5 n1 n6 n3 1
  19. 19. breadth-first traversal n4 n2 n5 n1 n6 n3 2 1
  20. 20. breadth-first traversal n4 n2 n5 n1 n6 n3 2 3 1
  21. 21. breadth-first traversal n4 n2 n5 n1 n6 n3 2 3 4 1
  22. 22. breadth-first traversal n4 n2 n5 n1 n6 n3 2 3 4 5 1
  23. 23. breadth-first traversal n4 n2 n5 n1 n6 n3 2 3 4 65 1
  24. 24. n4 n2 n5 n1 n6 n3 preorder(node) visit(node). preorder(node.left). preorder(node.right).
  25. 25. n4 n2 n5 n1 n6 n3 1 preorder(node) visit(node). preorder(node.left). preorder(node.right).
  26. 26. n4 n2 n5 n1 n6 n3 2 1 preorder(node) visit(node). preorder(node.left). preorder(node.right).
  27. 27. n4 n2 n5 n1 n6 n3 2 3 1 preorder(node) visit(node). preorder(node.left). preorder(node.right).
  28. 28. n4 n2 n5 n1 n6 n3 2 3 4 1 preorder(node) visit(node). preorder(node.left). preorder(node.right).
  29. 29. n4 n2 n5 n1 n6 n3 2 5 3 4 1 preorder(node) visit(node). preorder(node.left). preorder(node.right).
  30. 30. n4 n2 n5 n1 n6 n3 2 5 3 64 1 preorder(node) visit(node). preorder(node.left). preorder(node.right).
  31. 31. n4 n2 n5 n1 n6 n3 inorder(node) inorder(node.left). visit(node). inorder(node.right).
  32. 32. n4 n2 n5 n1 n6 n3 1 inorder(node) inorder(node.left). visit(node). inorder(node.right).
  33. 33. n4 n2 n5 n1 n6 n3 2 1 inorder(node) inorder(node.left). visit(node). inorder(node.right).
  34. 34. n4 n2 n5 n1 n6 n3 2 1 3 inorder(node) inorder(node.left). visit(node). inorder(node.right).
  35. 35. n4 n2 n5 n1 n6 n3 2 1 3 4 inorder(node) inorder(node.left). visit(node). inorder(node.right).
  36. 36. n4 n2 n5 n1 n6 n3 2 1 53 4 inorder(node) inorder(node.left). visit(node). inorder(node.right).
  37. 37. n4 n2 n5 n1 n6 n3 2 6 1 53 4 inorder(node) inorder(node.left). visit(node). inorder(node.right).
  38. 38. n4 n2 n5 n1 n6 n3 postorder (node) postorder(node.left). postorder(node.right). visit(node).
  39. 39. n4 n2 n5 n1 n6 n3 1 postorder (node) postorder(node.left). postorder(node.right). visit(node).
  40. 40. n4 n2 n5 n1 n6 n3 1 2 postorder (node) postorder(node.left). postorder(node.right). visit(node).
  41. 41. n4 n2 n5 n1 n6 n3 3 1 2 postorder (node) postorder(node.left). postorder(node.right). visit(node).
  42. 42. n4 n2 n5 n1 n6 n3 3 1 42 postorder (node) postorder(node.left). postorder(node.right). visit(node).
  43. 43. n4 n2 n5 n1 n6 n3 3 5 1 42 postorder (node) postorder(node.left). postorder(node.right). visit(node).
  44. 44. n4 n2 n5 n1 n6 n3 3 5 1 42 6 postorder (node) postorder(node.left). postorder(node.right). visit(node).
  45. 45. !"#$%&'(")$* ! "#$#%&'!&$()*+,%&)$!&-!.,--#/!)$!(*)+!0#$#*,%&)$!%)! Example (group 15)
  46. 46. !"#$%&'(")$* ! "#$#%&'!&$()*+,%&)$!&-!.,--#/!)$!(*)+!0#$#*,%&)$!%)! Example (group 15)
  47. 47. Hierarchical structure
  48. 48. Binary search tree n4 n2 n5 n1 n6 n3 2 6 1 53 4
  49. 49. n4 n2 n5 n1 n6 n3 2 61 53 4
  50. 50. n4 n2 n5 n1 n6 n3 2 61 53 4
  51. 51. n4 n2 n5 n1 n6 n3 2 6 1 53 4
  52. 52. n4 n2 n5 n1 n6 n3 2 6 1 5 3 4
  53. 53. Binary search tree n4 n2 n5 n1 n6 n3 2 6 1 53 4
  54. 54. a + b - c * d
  55. 55. a + b - c * d
  56. 56. a + b - c * d
  57. 57. a + b - c * d operator operand
  58. 58. Infix notation a + b - c * d Postfix notation Prefix notation
  59. 59. Infix notation a + b - c * d Postfix notation Prefix notation -+ab*cd
  60. 60. Infix notation a + b - c * d a+b-c*d Postfix notation Prefix notation -+ab*cd
  61. 61. Infix notation a + b - c * d a+b-c*d Postfix notation ab+cd*- Prefix notation -+ab*cd
  62. 62. Tudor Gîrba www.tudorgirba.com creativecommons.org/licenses/by/3.0/

×