Computer Science 112:

Introduction to Computer Science II

Gregory M. Kapfhammer


flickr photo by by physician1977 shared under a CC Public Domain Dedication (CC0)

Color Scheme

Key Concept

Corresponding Diagram

In-Class Discussion

In-Class Activity

Details in the Textbook

Linear data structures

Hierarchical data structures

Trees are like linked lists but ...

... they have "parent child" relationships!

Benefits of using trees?

Drawbacks of using trees?

Tree Type

A tree is a set of nodes

It stores data elements hierarchically

It contains a root node

It contains internal/external node(s)

The nodes have a parent-child relationship

What does this look like in memory?


flickr photo shared by Derek Severson under a Creative Commons ( BY-NC-ND ) license

Tree Type

A node can have an ... ancestor

... sibling

... descendant

A tree can contain a ... subtree

... a path of nodes

Any questions about trees?


flickr photo shared by Derek Severson under a Creative Commons ( BY-NC-ND ) license

Ordered trees

Un-ordered trees

Trade-offs of ordering?

Depth of a node = number of ancestors

Tree height = depth of "deepest" node

Binary trees

General trees

Tree traversal

Any questions about trees?

We will investigate these issues in assignments!