【DataStructure】Description and Introduction of Tree

【Description】

At ree is a nonlinear data structure that models a hierarchical organization. The characteristic eatures are that each element may have several successors (called its “children”) and every element except one (called the “root”) has a unique predecessor (called its “parent”). Trees are common in computer science: Computer file systems are trees, the inheritance structure for Java classes is a tree, the run-time system of method invocations during the execution of a Java program is a tree, the classification of Java types is a tree, and the actual syntactical definition of the Java programming language itself forms a tree.

【Theorem】

【TreesType】

? A decision tree is a tree diagram that summarizes all the differents possible stages of a process that solve a problem by means of sequence of decisions. Rach internal node is a labeled with a question, each arc is laeled with an answer to its question, and each leaf node is labeled with the solution to the problem.

Five coins that appear identical are to be tested to determine which one of them is counterfeit. The only feature that distinguishes that the counterfeit coins is that it weights less than that the legitimate coins.

? A transition diagram is a tree or graphj whose internal nodes represent different states or situations that may occur during a multistage process. As in a decision tree, each leaf represents a diffenert outcome from the process. Each branch is labeled with the conditional probability that the resulting child event will occur., given that the parent event has occurred.

? Orredered trees

Here is the recursive definition of an ordered tree:

Anordered treeis either the empty set or a pair T= (r, S), where ris a node 

andSis a sequence of disjoint ordered trees, none of which contains r.

The node ris called the rootof the tree T, and the elements of the sequence Sare its subtrees.

【Traversal Algorithms】

A traversal algorithm is a method for processing a data structure that applies a given operation to each element of the structure. For example, if the operation is to print the contents of the element, then the traversal would print every element in the structure. THe process of applying the operation to the each element is called visiting the element. So executing the traversal algorithm causes each element in the structure to be visited.There are three common algorithms for traversing a general tree.

? Level order traversal

Thelevel order traversalalgorithm visits the root, then visits each element on the first level,

then visits each element on the second level, and so forth, each time visiting all the elements on one level before going down to the next level. If the tree is drawn in the usual manner with its root at the top and leaves near the bottom, then the level order pattern is the same left-to-right top-to-bottom pattern that you follow to read English text.

The level order traversal of the tree shown in above figure would visit the nodes in the following order: a, b,c,d, e, f, g, h,i,j, k, l, m.

? The preorder traversal

The preorder traversal algorithm visits the root first and then does a preorder traversal recursively to each subtree in order.

The preorder traversalof the tree shown in above figure would visit the nodes in this order: a,b,e, h,i,f, c, d, g, j, k,l, m.

? The postorder traversal

The postorder traversal algorithm does a postorder traversal recursively to each subtree before visiting the root.

The postorder traversal of the tree shown in figure would visit the nodes in the following order: h,i,e,f,b,c,j,k,l,m,g,d,a

【DataStructure】Description and Introduction of Tree,布布扣,bubuko.com

时间: 2024-10-26 15:07:20

【DataStructure】Description and Introduction of Tree的相关文章

【DataStructure】Description and usage of queue

[Description] A queue is a collection that implements the first-in-first-out protocal. This means that the only accessiable object in the collection in the first one that was inserted. The most common example of a queue is a waiting line. [Interface]

【DataStructure】The description of Java Collections Framework

The Java Connections FrameWork is a group of class or method and interfacs in the java.util package. Its main purpose is to provide a unified framework for implementing common data structure. A collections is a object that contains other objects,whic

【DataStructure】Implemantation of Binary Tree

Statements: This blog was written by me, but most of content  is quoted from book[Data Structure with Java Hubbard] Here is a class for binary trees that directly implements the recursive definition. By extending the AbstractCollectionclass, it remai

【DataStructure】The description of generic collections

In this blog, generic collections will be talked about  in details.  In the past bacause of shortage of generic argument,  less importance has been attached to the this module. Just now after reading the chapter about this knowledge, I gradually real

【DataStructure】The description and usage of Stack

A stack is collection that implements the last-in-first-out protocal.This means that the only access object in the collections is the last one thatwas inserted.The fundamental  operations of a stack are: add an element onto the top of stack, access t

【DataStructure】One of queue usage: Simulation System

Statements: This blog was written by me, but most of content  is quoted from book[Data Structure with Java Hubbard] [Description] This simulationillustrates objectoriented programming(OOP). Java objects are instantiated to represent all the interacti

【DataStructure】Another usage of List: Polynomial

Statements: This blog was written by me, but most of content  is quoted from book[Data Structure with Java Hubbard] [Description] Apolynomialis a mathematical function of the form: p(x) = a0xn+ a1xn–1+a2xn–2+ ???+an–1x + an The greatest exponent, 

【DataStructure】 Classical Question: Josephus Cycle

[Description] This problem is based upon a report by the historian Joseph ben Matthias (Josephus) on the outcome of a suicide pact that he had made between himself and 40 soldiers as they were besieged by superior Roman forces in 67 A.D. Josephus pro

【DataStructure】Descriptioin and usage of List

Statements: This blog was written by me, but most of content  is quoted from book[Data Structure with Java Hubbard] [Description] Alistis a collection of elements that are accessible sequentially: the first element, followed by the second element, fo