17-binary_tree

# 17-binary_tree - CSE143 Lecture17 BinaryTrees

This preview shows pages 1–8. Sign up to view the full content.

CSE 143 Lecture 17 Binary Trees slides created by Marty Stepp and Alyssa Harding http://www.cs.washington.edu/143/

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

View Full Document
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. binary tree  can be defined as either: empty ( null ), or root  node that contains: data left  subtree, and right  subtree. (The left and/or right subtree could be empty.) 7 6 3 2 1 5 4 root
3 Definition is recursive! The recursive definition lets us build any shape tree:

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

View Full Document
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
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."

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

View Full Document
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
7 Terminology child : Any node our node  refers to parent : the node that refers

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 09/29/2010 for the course CSE 143 taught by Professor Sr during the Spring '08 term at University of Washington.

### Page1 / 20

17-binary_tree - CSE143 Lecture17 BinaryTrees

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

View Full Document
Ask a homework question - tutors are online