lecture05trees1 - Trees Trees Binary tree and Binary tree...

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

View Full Document Right Arrow Icon
1 Trees Trees Binary tree and Binary tree traversals Expression trees Infix, Postfix, Prefix notation Binary Search Trees Operations supported Complexity
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 (Directed) Tree 7 6 3 4 3 2 1 8 7 1 6 9 2 3 9 8 2 8 0 5 4 6
Background image of page 2
3 (undirected) tree Single path between any two nodes Removal of any edge disconnects the set of nodes Which node could be the root of a rooted tree?
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 Definition of Trees /\ is a tree. It is called an “empty tree”. If is a node and are non-empty trees where k 0, then is a tree. T 1 T 2 T k T 1 T 2 T k
Background image of page 4
5 Notation about Trees root, subtrees parent, child, sibling leaves, internal nodes edge path, length ancestor, descendant depth, height Root at depth 0, One node tree : height 0 Empty tree: height -1 7 6 3 4 3 2 1 8 8 2 8
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Tree criteria Always a single root A single path to every node Doesn’t matter how we draw it
Background image of page 6
7 Trees ? 4 A B C D E
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Game tree 1 2 7 2 1 3 8 6 X 1 2 7 2 1 X 8 6 3 1 2 7 2 1 3 8 X 6 Start state for the 8- puzzle; X marks the empty square. Can move the 3 tile into the empty square, or, can move the 6 tile into it. Goal of the game is to place all tiles in some special order. Will this tree ever “fold”?
Background image of page 8
9 What about the tree of chess moves? How many choices for white’s first move? How many moves for black’s first response? How many nodes in the tree of all possibilities for 5 white moves and the 5 responses of black?
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 Binary Trees Binary tree : every node has at most 2 children (left child and right child) N-ary tree : no node has more than N children. Advantages? Disadvantages? 7 6 5 4 3 2 1 8
Background image of page 10
11 Some Properties of Binary Trees Suppose a binary tree has n nodes, and height h. The total numbers of nodes: h+1 n 2 h+1 -1 The height of the tree: (from inequality above) log(n+1)-1 h (n-1)
Background image of page 11

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

View Full DocumentRight Arrow Icon
12 Implementation of Binary Trees 7 6 5 4 3 2 1 8 x 2 1 7 8 3 4 6 5
Background image of page 12
13 Binary Trees (expression tree) LL INFO RL node T L R (((a+b)*(c+(d-3))) LL: left link RL: Right Link * + + - d 3 a b c T
Background image of page 13

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

View Full DocumentRight Arrow Icon
14 Implementation of N-ary Trees 7 6 4 3 4 8 2 8 5 x
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/25/2008 for the course CSE 331 taught by Professor M.mccullen during the Spring '08 term at Michigan State University.

Page1 / 46

lecture05trees1 - Trees Trees Binary tree and Binary tree...

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

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