重庆大学数据结构英文课件Trees_04
- 格式:pdf
- 大小:646.08 KB
- 文档页数:27
Introduction to Trees(3)Course informationTitle Data Structure (tree) Speaker Xiong QianDepartment Electronic and informationengineeringInstrument multimediaDate Mon, 14/5 Time 90 minutes Learning Objectives1 One application of binary tree--expression trees2 Comprehend the concept and the process of threaded binary treesKey Point1 threaded binary treesWay of TeachingPlan to give the lecture by clear explanation with particular examples.Make use of all kinds of instruments especially multimedia.To attract the attention of students through putting questions and other interactive method.Try to lead the students their way of thinking.Course Layout1. review Tree(1、2) 3 minutes2.new content 1.expression trees 35 minutes2. threaded binary trees50 minutes3. summary 1.review the key points and the difficulties2.questions from students3.homework2 minuteContent7-5 EXPRESSION TREESOne interesting series of binary tree applications are expression trees. An expression is a sequence of tokens that follow prescribed rules. A token may be either an operand or an operator. In this discussion, we consider only binary arithmetic operators in the form operand-operator-operand. The standard arithmetic operators are + _* /An expression tree is a binary tree with the following properties:1. Each leaf is an operand.2. The root and internal nodes are operators.3. Subtrees are subexpressions, with the root being an operator.Figure 7-15 is an infix expression and its expression tree.For an expression tree, the three standard traversals represent the three different expression formats: infix. postfix, and prefix. The inorder traversal produces the infix expression, the postorder traversal produces the postfix expression, and the preorder traversal produces the prefix expression.Infix TraversalTo demonstrate the infix traversal of an expression tree, let’s write an algorithm that traverses the tree and prints the expression. When we print the infix expression tree, we must add an opening parenthesis at the beginning of each expression and a closing parenthesis at the end of each expression. Because the root of the tree and each of its subtrees represent a subexpression, we print the opening parenthesis when we start a tree or subtree and the closing parenthesis when we have processed all of its children. Figure 7-16 shows the placement of the parentheses as we walk through the tree using an inorder traversal.Postfix TraversalThe postfix traversal of an expression uses the basic postorder traversal of any binary tree. Note that it does not require parentheses. The pseudocode is shown In Algorithm 7-7.Prefix TraversalThe final expression tree traversal is the prefix traversal. It uses the standard preorder tree traversal. Again, no parentheses are necessary. The pseudocode is shown in Algorithm 7-8.7-6 THREADED BINARY TREE中文补充。