Trees by Michael Co

Trees by Michael Co - CS216: Program and Data...

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

View Full Document Right Arrow Icon
CS216: Program and Data Representation University of Virginia Computer Science Fall 2006 Michele Co Classes 10-11: Trees http://www.cs.virginia.edu/cs216 A few slides used from D. Evans, S’06 2 UVa CS216 Trees: Main Points • Definitions and terminology • Types of trees –Binary trees –Binary search trees –AVL trees • Tree traversals –pre-order –post-order –in-order 3 UVa CS216 Data Structures • If we have a good list implementation, do we need any other data structures? • For computing: no –We can compute everything with just lists (actually even less). The underlying machine memory can be thought of as a list. •For thinking : yes –Lists are a very limited way of thinking about problems. 4 UVa CS216 List Limitations L Node Info: Next: 1 Node Info: Next: 2 Info: Next: 3 Node In a list, every element has direct relationships with only two things: predecessor and successor Access time: O(n) Goal: O(log n) 5 UVa CS216 Complex Relationships Bill Cheswick’s Map of the Internet http://research.lumeta.com/ches/map/gallery/ 6 UVa CS216 List Tree • List: each element has relationships with up to 2 other elements: • Binary Tree: each element has relationships with up to 3 other elements: Element Predecessor Successor Element Parent Right Child Left Child List is a special case of Tree
Background image of page 1

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

View Full DocumentRight Arrow Icon
7 UVa CS216 Tree Terms English German Anglo-Saxon Norwegian Czech Spanish Italian Romanian French Leaf Root Note that CS trees are usually drawn upside down! Height = 3 Height = 0 Depth = 4 Sibling 8 UVa CS216 Tree Terms Root : a node with no parent –There can only be one root Leaf : a node with no children Sibling : same parent Height of a Node: length of the longest path from that node to a leaf Height of a Tree: maximum depth of a node in that tree = height of the root Depth of a Node: length of the path from the Root to that node 9 UVa CS216 More Tree Terms Path: sequence of nodes n 1 , n 2 , …, n k such that n i is parent of n i+1 for 1 i k
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

Trees by Michael Co - CS216: Program and Data...

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

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