数据结构-tree.ppt

数据结构-tree

Data Structure Software College Northeastern University Chapter 6 Tree Overview What is Tree Tree Terminology Tree ADT Binary Trees Binary Tree ADT Storing Binary Trees Binary Tree Traversals Applications of Binary Tree Storing Trees Tree Traversals Huffman Code Tree Nature View of a Tree Computer Scientist’s View What is a Tree A tree is a finite nonempty set of elements. It is an abstract model of a hierarchical structure. consists of nodes with a parent-child relation. Applications: Organization charts File systems Programming environments What is a Tree:Examples What is a Tree:Examples Tree Terminology Root: node without parent (A) Siblings(兄弟): nodes share the same parent Internal node(内部结点): node with at least one child (A, B, C, F) External node (leaf ): node without children (E, I, J, K, G, H, D) Ancestors (祖先)of a node: parent, grandparent, grand-grandparent, etc. Descendant(后裔) of a node: child, grandchild, grand-grandchild, etc. Tree Terminology Depth of a node: number of ancestors Height of a tree: maximum depth of any node Degree of a node: the number of its children Degree of a tree: the maximum number of its node. Subtree: tree consisting of a node and its descendants Tree Properties Tree ADT We use positions to abstract nodes Generic methods: integer size() boolean isEmpty() objectIterator elements() positionIterator positions() Accessor methods: position root() position parent(p) positionIterator children(p) Binary Tree A binary tree is a tree with the following properties: Each internal node has at most two children (degree of two) The children of a node are an ordered pair Binary Tree We call the children of an internal node left child and right child Alternative recursive definition: a binary tree is either a tree consisting of a single node, OR a tree whose root has an ordered pair of children, each of which is a binary tree Applications: arithmetic expressions decision processes searching Arithmetic Expression Tree Binary

文档评论(0)

1亿VIP精品文档

相关文档