Trees

# Trees - CSE205 Concepts of Computer Science and Data...

This preview shows pages 1–14. Sign up to view the full content.

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE205 Concepts of Computer Science and Data Structure Chapter 16- Modified for CSE205- Fall 2008 Outline Tree Terminology Tree Traversals Strategies for Tree Implementations Binary Tree Implementation Tree Terminology A tree is a non-linear structure in which elements are organized into a hierarchy Tree is comprised of a set of nodes in which elements are stored and edges connect one node to another Each node is located on a particular level There is only one root node in the tree Tree Terminology Nodes at the lower level of a tree are the children of nodes at the previous level A node can have only one parent , but may have multiple children Nodes that have the same parent are siblings The root is the only node which has no parent Tree Terminology A node that has no children is a leaf node A note that is not the root and has at least one child is an internal node A subtree is a tree structure that makes up part of another tree We can follow a path through a tree from parent to child, starting at the root A node is an ancestor of another node if it is above it on the path from the root. Tree Terminology Nodes that can be reached by following a path from a particular node are the descendants of that node The level of a node is the length of the path from the root to the node A B C E D F G Level 1 3 2 Tree Terminology The path length is determined by counting the number of edges that must be followed to get from the root to the node The height (or depth ) of a tree is the length of the longest path from the root to a leaf Tree Classifications Trees can be classified in many ways One important criteria is the maximum number of children any node in the tree may have This is sometimes referred to as the order of the tree General trees have no limit to the number of children a node may have A tree that limits each node to no more than n children is referred to as an n-ary tree Tree Classifications Trees in which nodes may have at most two children are called binary trees A tree is considered to be balanced if all of the leaves of the tree are on the same level or at least within one level of each other Tree Classifications A balanced n-ary tree with m elements will have a height of log n m A balanced binary tree with n nodes has a height of log 2 n An n-ary tree is full if all leaves of the tree are at the same height and every non-leaf node has exactly n children A tree is complete if it is full, or full to the next-to-last level with all leaves at the bottom level on the left side of the tree Some Complete Trees Outline Tree Terminology Tree Traversals Strategies for Tree Implementations Binary Tree Implementation Tree Traversals Because of the non-linear nature of a tree, traversing a tree is generally more interesting than traversing a linear structure The concept of visiting a node is somewhat vague and...
View Full Document

## This note was uploaded on 06/11/2009 for the course CS 205214 taught by Professor Balasooriya/kouvetakis during the Spring '09 term at ASU.

### Page1 / 40

Trees - CSE205 Concepts of Computer Science and Data...

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

View Full Document
Ask a homework question - tutors are online