11b.Trees1_Slides

11b.Trees1_Slides - Introduction to Trees CS 103B Stanford...

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

View Full Document Right Arrow Icon
Trees I 1 Introduction to Trees CS 103B Stanford University April 28, 2008
Background image of page 1

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

View Full DocumentRight Arrow Icon
Trees I 2 Outline ± Hierarchical Structures ± Tree Terminology ± Trees and Recursion ± Heaps
Background image of page 2
Trees I 3 Hierarchical Structures ± Conceptual tool for representing relationships among certain classes of items ± Relationship of the elements is one to many Family 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
Trees I 4 Hierarchical Structures ± Compiler uses trees for representing algebraic expressions (unambiguous order of evaluation) ± Other applications: ² File systems ² Organizational Charts
Background image of page 4
Trees I 5 Terminology ± Node or Vertex: elements of a tree ± Root: unique first node that has no predecessors but may have many successors ± Leaves : nodes that have no successors but have one unique predecessor ± Each node that is neither a root nor a leaf has a unique predecessor, called the parent node, and at least one successor, called a child node. An internal node is any node that is not a leaf (so this includes the root)
Background image of page 5

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

View Full DocumentRight Arrow Icon
Trees I 6 More Terminology ± Subtree ± Height ² Height = Level – 1 ± Ancestor (of node n) ± Descendent (of node n)
Background image of page 6
Trees I 7 Binary Trees ± Each node has exactly 0, 1 or 2 children (eg. expression tree) ± Recursive definition: T is a binary tree if either 1. T has no nodes, or 2. T is of the form
Background image of page 7

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

View Full DocumentRight Arrow Icon
Trees I 8 Binary Search Trees (BST) ± A binary tree that is "sorted" according to some particular order ± For each node n in a BST the following three properties must be satisfied : - n's value is greater than all the values in its left subtree - n's value is less than all the values in its right subtree - both T(left) and T(right) are binary trees ± Searching BST for an item is similar to a binary search
Background image of page 8
Trees I 9 Searching BST ± Find Wesley ± Contrast with linear search
Background image of page 9

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

View Full DocumentRight Arrow Icon
Trees I 10 Recursion ±
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 27

11b.Trees1_Slides - Introduction to Trees CS 103B Stanford...

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

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