DA08 - Trees' Basics CSC 3102 1 B.B. Karki, LSU Definition...

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

View Full Document Right Arrow Icon
B.B. Karki, LSU 1 CSC 3102 Trees’ Basics
Background image of page 1

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

View Full DocumentRight Arrow Icon
B.B. Karki, LSU 2 CSC 3102 Definition and Concepts A tree consists of a finite set of elements, called nodes , and a finite set of directed lines, called branches , that connect the nodes. Degree of node = Number of branches = Sum of indegree and outdegree branches Each node can have an indegree of exactly one but an outdegree of zero, one or more. Only one predecessor but multiple successors. The level of the node is its distance from the root. The height of a tree is the level of the leaf in the longest path from the root plus one. Height (or depth) = 3 Different nodes: Parents: A, B, F Children: B, E, F, C, D, G, H, I Siblings: {B, E, F}, {C,D}, {G,H,I} Leaves: C, D, E, G, H, I Internal nodes: B, F Path from the root to the leaf I is AFI. Subtree: any connected structure below the root BCD, E, FGHI Recursive definition: A tree is a set of nodes that is either empty or has a designated node called the root from which hierarchically descend zero or more subtrees, which are also trees. B E F C D G H I A Root at level 0 Branch FI Branch AF
Background image of page 2
B.B. Karki, LSU 3 CSC 3102 Binary Trees A binary tree is one in which a node can have zero or one or two subtrees and each subtree is itself a binary tree. A binary tree node can not have more than two subtrees. Symmetry is not a tree requirement. B E C D F A Left subtree Right subtree Height of a binary tree: h max = N ; h min = log 2 N + 1 For a given height h , N min = h and N max = 2 h -1 Balance factor is the difference in height between the left and right subtrees: B = h L - h R B = 0 for the above binary tree but B is not zero for all its eight subtrees. A tree is balanced if its B is zero, -1 or 1 and its subtrees are also balanced. Node structure: Node leftSubTree <pointer to Node> data <dataType> rightSubTree <pointer to Node> End Node Class Node left <reference to Node> data <dataType> right <reference Node> End Node
Background image of page 3

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

View Full DocumentRight Arrow Icon
B.B. Karki, LSU 4 CSC 3102 Binary Tree Traversals Two general approaches for visiting nodes of a tree: DFT: Depth-First-Traversal
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/06/2009 for the course CSC 3102 taught by Professor Kraft,d during the Fall '08 term at LSU.

Page1 / 13

DA08 - Trees' Basics CSC 3102 1 B.B. Karki, LSU Definition...

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

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