{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

19-binary_tree - CSE 143 Lecture 19 Binary Trees read 17.1...

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

View Full Document Right Arrow Icon
CSE 143 Lecture 19 Binary Trees read 17.1 - 17.2 slides created by Marty Stepp http://www.cs.washington.edu/143/
Background image of page 1

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

View Full Document Right Arrow Icon
2 Creative use of arrays/links • Some data structures (such as hash tables and binary trees) are built around clever ways of using arrays and/or linked lists. What array order can help us find values quickly later? What if linked list nodes each had more than one link? 0 3 24 4 0 5 0 6 7 7 0 8 49 0 11 0 value 9 2 1 0 index front back 24 49 11 7
Background image of page 2
3 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 : One where each node has at most two children. • A 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 3

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

View Full Document Right Arrow Icon
4 Trees in computer science • folders/files on a computer • family genealogy; organizational charts • AI: decision trees • compilers: parse tree a = (b + c) * d; • cell phone T9 d + * a = c b
Background image of page 4
5 Programming with trees • Trees are a mixture of linked lists and recursion considered very elegant (perhaps beautiful!) by CSE nerds 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."
Background image of page 5

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

View Full Document Right Arrow Icon
6 Terminology node : an object containing a data value and left/right children root : topmost node of a tree leaf : a node that has no children branch
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}