[Instructions] [Search] [Current] [News] [Syllabus] [Glance] [Links] [Handouts] [Project] [Outlines] [Labs] [Assignments] [Quizzes] [Exams] [Examples] [EIJ] [JPDS] [Tutorial] [API]

Back to Project Discussion. On to Implementing Trees.

**Held** Monday, April 24, 2000

**Overview**

Today, we generalize the heap and the search tree into a generic tree data structure.

**Notes**

- I was hoping to grade assignment 5 over the weekend. Unfortunately, as in all holiday weekends, the time evaporated.
- Are there project questions?

**Contents**

**Summary**

- Heaps and search trees, revisited
- Representing arithmetic expressions
- Evaluating expressions

- Generalizing: a binary tree ADT
- Generalizing further: a tree ADT

- Until recently, all of the ``ordered'' structures we considered (lists, arrays, vectors, stacks, and queues) were somewhat linear (in an informal rather than a formal sesnse).
- What makes a structure linear?
- Exactly
**one***first*element. - Exactly
**one***last*element. - Each element (except the first) has exactly
**one***predecessor*. - Each element (except the last) has exactly
**one***successor*.

- Exactly
- Search trees and heaps had a somewhat different structure. How are
search trees Different?
- There is still exactly
**one***first*element. - There are now
**many***last*elements. - Each element (except the first) still has exactly
**one***predecessor*. - Each element (except the last) may have
**many**(okay, two)*successors*.

- There is still exactly
- By careful consideration of such restrictions, we can develop a number of different interesting structures.

- We can generalize search trees to develop a data structure commonly called
*trees*. - Trees are a collection of values,
- stored in
*nodes*, - with a designated
*root*(first element) - and a number of
*leaves*(``last'' elements). - Every non-leaf node has one or more
*children*(successors) - and the leaves have zero children,
- Every nonroot node has exactly one
*parent*(previous element) - and the root has no parents.

- stored in
- In
*binary trees*, each node can have at most two children, often designated as*left*and*right*.

- There are many ways in which trees are used, including,
- search trees, which are used to store information for retrieval;
- decision trees, which are used to describe decision processes;
- class hierarchies, which show the relationships between classes in a single-inheritance language like Java;
- representing arithmetic expressions, using operators for internal nodes and values for leaves; and even
- program trees, which show the structure of a program.

- You've already seen
*binary search trees*:- A node stores a value.
- All smaller values are in the left subtree.
- All larger values are in the right subtree.

- You've also seen
*heaps*:- The root stores the smallest value.
- The left and right subtrees are also heaps.
- The tree is nearly-complete.

- Trees are good for hierarchical structures, like advising relationships in graduate school.

- Purposefully left open. I'm going to ask you to design this one.
- The basics so far:
__public____interface__Tree {**/** * Add another child to a vertex in the tree. * Pre: The vertex (parent) is in the current tree. * Post: The vertex (parent) has another child. The new child * contains newThing. */**__public____void__add(Object newThing, Vertex parent)__throws__Exception;**/** * Get the root of the tree. */**__public_________ getRoot(); }

Tuesday, 18 January 2000

- Created as a blank outline.

Monday, 24 April 2000

- Filled in some details. These are based primarily on outline 45 of CSC152 99S.

Tuesday, 25 April 2000

- Updated to better represent what happened.

Back to Project Discussion. On to Implementing Trees.

[Instructions] [Search] [Current] [News] [Syllabus] [Glance] [Links] [Handouts] [Project] [Outlines] [Labs] [Assignments] [Quizzes] [Exams] [Examples] [EIJ] [JPDS] [Tutorial] [API]

**Disclaimer** Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/2000S/Outlines/outline.45.html

Source text last modified Tue Apr 25 08:37:41 2000.

This page generated on Tue Apr 25 08:54:39 2000 by Siteweaver. Validate this page's HTML.

Contact our webmaster at rebelsky@grinnell.edu