DS-chapter4(Binary Tree)

DS-chapter4(Binary Tree) - CHAPTER 4 TREES 4.1...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
CHAPTER 4 TREES 4.1 Preliminaries 1. Terminology Lineal Tree Pedigree Tree ( binary tree )
Background image of page 1

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

View Full Document Right Arrow Icon
Preliminaries H Definition R A tree is a collection of nodes. The collection can be empty; otherwise, a tree consists of (1) a distinguished node r , called the root ; (2) and zero or more nonempty (sub)trees T 1 , ⋅ ⋅ ⋅ , T k , each of whose roots are connected by a directed edge from r . Note: Subtrees must not connect together. Therefore every node in the tree is the root of some subtree. There are edges in a tree with N nodes. Normally the root is drawn at the top. N - 1
Background image of page 2
A C B D G F E H I J M L K degree of a node ::= number of subtrees of the node. For example, degree(A) = 3, degree(F) = 0. degree of a tree ::= For example, degree of this tree = 3. { } ) node ( degree max tree node leaf ( terminal node ) ::= a node with degree 0 (no children). parent ::= a node that has subtrees. children ::= the roots of the subtrees of a parent. siblings ::= children of the same parent. Preliminaries
Background image of page 3

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

View Full Document Right Arrow Icon
Preliminaries A C B D G F E H I J M L K ancestors of a node ::= all the nodes along the path from the node up to the root. descendants of a node ::= all the nodes in its subtrees. depth of n i ::= length of the unique path from the root to n i . Depth(root) = 0. height of n i ::= length of the longest path from n i to a leaf. Height(leaf) = 0, and height(D) = 2. height (depth) of a tree ::= height(root) = depth(deepest leaf). path from n 1 to n k ::= a ( unique ) sequence of nodes n 1 , n 2 , …, n k such that n i is the parent of n i+ 1 for 1 i < k . length of path ::= number of edges on the path.
Background image of page 4
Implementation of trees A C B D G F E H I J M L K ( A ) ( A ( B, C, D ) ) ( A ( B ( E, F ), C ( G ), D ( H, I, J ) ) ) ( A ( B ( E ( K, L ), F ), C ( G ), D ( H ( M ), I, J ) ) ) A B C D E F G H I J K L M So the size of each node depends on the number of branches. Hmmm.
Background image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 25

DS-chapter4(Binary Tree) - CHAPTER 4 TREES 4.1...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online