trees 10

# trees 10 - Trees Why Trees We need a representation for...

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

Trees

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

View Full Document
Trees 2 Why Trees? We need a representation for hierarchical data. Like what? ancestor – descendent superior – subordinate whole – part modular organization Definition: A tree t is a finite nonempty set of elements. One element is called the root , and all the remaining elements are partitioned into trees called subtrees.
Trees 3 Tree Terms Elements are represented as nodes …usually drawn as a circle. Edges , lines, are drawn connecting a node to its subtree. This edge implies a relationship between nodes. A node can be a parent node or a child node. Other terms used to describe the relationship between nodes are: sibling, ancestor/descendent, grandchild/grandparent A leaf is an element with no children The term level is used to denote the tier of an element within a tree. The root is at level 1; its children are at level 2…and so on. The degree of an element is the number of kids it has. The degree of a tree is the max of its elements’ degrees.

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

View Full Document
Trees 4 There are many types of trees: Binary Trees Binary Search Trees AVL Trees Red-Black Trees B-Trees
Trees 5 Binary Trees A binary tree t is a finite, but possibly empty, collection of elements. When the tree is not empty, it contains a root , and all the remaining elements are partitioned into sub binary trees , which are called the left and right subtrees of t. How does a binary tree differ from a tree? We can use a binary tree to represent arithmetic expressions.

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

View Full Document
Trees 6 A full binary tree is a binary tree in which all the leaves are on the same level and every nonleaf node has 2 children. It has height h and contains exactly 2 h - 1 elements. A complete binary tree is either full or full through the next-to-last level, with the leaves on the last level as far to the left as possible. A full binary tree is a special case of a complete
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 22

trees 10 - Trees Why Trees We need a representation for...

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

View Full Document
Ask a homework question - tutors are online