26 - CMPSCI 187:Programming With Data Structures Lecture...

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

View Full Document Right Arrow Icon
CMPSCI 187:Programming With Data Structures Lecture #26: Trees: Defnition and Implementation 16 November 2011
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: Defnition and Implementation • Tree Vocabulary • Basic Strategies to Implement Trees • Ways to Traverse a Tree • Implementing Trees with Links • Implementing Trees with Arrays
Background image of page 2
Tree Vocabulary • Trees are made up of nodes . The key property of a tree is that every node except for one, the root , has exactly one parent . We use genealogical language throughout, so that children of the same node are siblings , a node that can be reached by following parent pointers is an ancestor , and a node whose ancestor you are is your descendent . • Nodes with no children are called leaves , and nodes with children are internal nodes . The root is at level 0 , and the level of any other node is the number of parent pointers you must follow to reach the root. The height of a tree is the largest level number of any node in it. • A tree is binary if every internal node has either one or two children, and it is k-ary if every node has at most k children. L&C often implicitly assume that every internal node has exactly two children, but this isn’t a math course. ..
Background image of page 3

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

View Full DocumentRight Arrow Icon
Kinds of Binary Trees • A binary tree is called balanced in L&C if its leaves are all on one level or on two adjacent levels. A balanced tree of height h has at most 2^h leaves, and the fewest it can have (with no unary nodes) is 2^{h-1} + 1, still O(2^h). The height of a balanced tree with n leaves, or with n nodes, is O(log n). • L&C call a binary tree
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.

This note was uploaded on 11/22/2011 for the course COMPSCI 187 taught by Professor Barrington during the Fall '11 term at UMass (Amherst).

Page1 / 10

26 - CMPSCI 187:Programming With Data Structures Lecture...

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