Algorithms and OOD (CSC 207 2013F) : Outlines

# Outline 44: Trees, Generalized

Held: Wednesday, 20 November 2013

Summary

We generalize the binary search trees we have just studied.

Related Pages

Overview

• Trees, abstracted.

• I'll reserve time for questions.
• Upcoming extra credit opportunities:
• CS Department Talk, Today, Noon (with Pizza) Writing Bug-Free Code with Theorem Provers
• CS Table Friday, The New Curriculum
• Hamlet, Friday (7:30 pm), Saturday (7:30 pm), Sunday (2:00 pm)
• Typhoon Halyan Relief benefit show, Sunday, November 24th from 7-9pm in Harris. (If the entry fee is a burden, let me know and I'll give you the money.)
• "Data Sovereignty: The Challenge of Geolocating Data in the Cloud", November 25, 4:15 JRC 101
• "Gold Fever" by Andrew Sherburne '01 or so, 7:00 p.m., Monday, November 25, ARH 302
• Tuesday, November 26, 4:15 p.m., JRC 209 a gaming event with the game [d0x3d!]

• What are the big ideas of binary search trees?
• One I note is that we've found a new way of organizing memory.
• Not as a chunk of memory
• Not as a bunch of linked nodes
• But as a two-dimensional structure
• We might want to generalize the approach
• To help us think about a technique used for building data structures
• As an ADT that we can use to represent hierarchies
• That's right, we might use trees to implement non-tree ADTs (as in the case of BSTs implementing dictionaries), but we might also use other structures to implement things that we "think of" as trees.

## Trees, Abstracted

• Philosophy
• A tree is a hierarchical collection of items
• One item is designated the root of the tree
• Each item has 0 or more children
• Each item other than the root has exactly one parent
• The child/parent relationship is symmetric - a C is a child of P, then P is the parent of C
• We call the number of children the arity of a item
• An item with no children is a leaf
• The depth of a node is the number of parent links one must follow in order to reach the root. (The root has depth zero.)
• The height of a tree is the maximum of the depth of its children.
• The size of a tree is the number of items in the tree.
• Use Cases
• We represent employees in a company
• We might want to know who an employee reports to
• We might want to know who an employee supervises
• We might want to know how many employees an employee supervises
• Design Questions
• What is an item? Can the same value appear multiple times in the tree?
• Are children ordered?
• Do we allow removal of items? (The meaning of removal can be confusing when we think about it as an ADT.)
• Methods
• To be designed in class

## A Linked Implementation of Trees

• We can probably generalize our BSTs to make general trees.
• Instead of separate fields for the left and right subtree, we'll use an array of all the children. (We could even use an ArrayList.)

Copyright (c) 2013 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit `http://creativecommons.org/licenses/by/3.0/` or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.