17-binary_tree - CSE 143 Lecture 17 Binary Trees slides...

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

View Full Document Right Arrow Icon
1 CSE 143 Lecture 17 Binary Trees slides created by Marty Stepp and Alyssa Harding http://www.cs.washington.edu/143/ 2 Trees tree : A directed, acyclic structure of linked nodes. directed : Has one-way links between nodes. acyclic : No path wraps back around to the same node twice. • A binary tree can be defined as either: – empty ( null ), or – a root node that contains: data , • a left subtree, and • a right subtree. – (The left and/or right subtree could be empty.) 7 6 3 2 1 5 4 root
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 3 Definition is recursive! • The recursive definition lets us build any shape tree: 4 Trees in computer science • folders/files on a computer • family genealogy; organizational charts • AI: decision trees • compilers: parse tree – a = (b + c) * d; d + * a = c b
Background image of page 2
3 5 Programming with trees • Trees are a mixture of linked lists and recursion – considered very elegant once understood – difficult for novices to master • Common student remark #1: – "My code doesn't work, and I don't know why." • Common student remark #2: – "My code works, and I don't know why." 6 Terminology root : topmost node of the tree leaf : node with no children branch : any internal node; neither the root nor a leaf 9 21 30 78 5 29 82 16 Leaf nodes Root node Branch nodes
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 7 Terminology child : Any node our node refers to parent : the node that refers to our node sibling : another child of the parent of our node 9 21 30 78 5 29
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

17-binary_tree - CSE 143 Lecture 17 Binary Trees slides...

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

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