当前位置:网站首页>Given the preorder traversal and the inorder traversal order of a binary tree, find the postorder traversal of the tree
Given the preorder traversal and the inorder traversal order of a binary tree, find the postorder traversal of the tree
2022-07-20 21:11:00 【Finger sucking original Zhang】
Reference resources :
【 data structure 】 Traversing the binary tree
subject
It is known that the preorder traversal order of a binary tree is ABCDEF, The order of traversal is CBAEDF, What is the post order traversal of this tree ?
Answer key
All three traversals start from the root node , Preorder traversal is to print first and then recurse left and right , All preorder traversal sequences are ABCDEF, First letter A It's the root node ; Then traverse the sequence from the middle order CBAEDF, You can know C and B yes A Node on the left subtree of ,E、D、F yes A Node on the right subtree of , We can get the following figure :
Then look at... In the preceding sequence C and B, First B Again C, therefore B Should be A The left child ,C Just say B My child , as for C yes B Left or right child , Look at the middle order sequence CBAEDF,C stay B Before printing , explain C yes B The left child , Pictured :
Let's look at the... In the preface E、D、F, Their order is ABCDEF, signify D yes A The right child ,E and F yes D The descendants of ( Be careful , One of them is not necessarily a child , It could also be a grandson ). Again, the middle order sequence is CBAEDF,E stay D The left side of the ,F On the right side , therefore E yes D The left child ,F yes D The right child , Pictured :
To avoid derivation errors , We'd better deduce the preorder and inorder traversal sequence again according to this tree . According to the binary tree structure diagram , Easily get the post order traversal as CBEFDA.
summary
Here we can get two properties of traversal of binary tree :
- We know the preorder traversal sequence and the middle order traversal sequence , You can only identify a binary tree ;
- We know the sequence of post order traversal and the sequence of middle order traversal , You can only identify a binary tree ;
Be careful : We know preorder and postorder traversal , You can't be sure of a binary tree .
边栏推荐
- DBC2000有什么作用?DBC2000的安装与配置
- 没想到MySQL还会问这些...
- LeetCode每日一题(396. Rotate Function)
- 【微信小程序】label(86/100)
- 新的 ES2022 规范终于发布了,我总结了8个实用的新功能
- Customize ViewGroup container horizontalscrollviewex
- Where is the scan function of mobile browser and what is its function
- 山西省第二届网络安全技能大赛(企业组)部分赛题WP(五)
- How can Web3 enterprises use tokens to motivate employees?
- pytest+yaml框架环境配置和使用教程
猜你喜欢
Test / development programmer interview how to talk about salary, tips
如何保障 MySQL 和 Redis 的数据一致性?
另类解读宏观形势:美联储或将很快结束加息进程,重回量化宽松?
Comment répondre aux exigences de sécurité de divers environnements en nuage à l'ère de l'économie numérique?
node、nvm、nrm、npm、yarn使用教程
How to make a reliable delay queue with redis (classic collection version)
QT下载安装教程
ENVI_ Idl: synthesize and linearly stretch the data band of FY-4 satellite, and generate TIFF format and JPEG format respectively
web:从10到1的编译大重构
Wechat applet map call (quick learning)
随机推荐
Hello, excuse me, the source system of the data integration job is SQLSEVER, and the table name is a keyword, which needs to be added in the sqlserver library
通信开销:限制RedisCluster规模的关键因素
ENVI_IDL: 对风云四号卫星数据波段合成和线性拉伸并分别生成TIFF格式和JPEG格式
Llvm pass PWN getting started (3)
防火墙相关
scrapy爬虫框架基础知识
生成器的使用原则及方法以及利用生成器实现简易项目(内含详细解说传参问题)
10000人游戏服务器怎么选?
Markdown如何实现表格的合并单元格
openworm项目编译
数字经济时代下如何满足多种云环境安全需求?
Leetcode daily question (396. rotate function)
Alternative interpretation of the macro situation: the Federal Reserve may soon end the process of raising interest rates and return to quantitative easing?
如何保障 MySQL 和 Redis 的数据一致性?
各位大佬,请问MySQL CDC 对于无主键表 怎么切片?
毕设项目系列教程-智慧校园管理系统
Pytest+yaml framework environment configuration and use tutorial
自定义ViewGroup容器HorizontalScrollViewEx
wsl2安装教程以及修改默认安装目录到其他盘
DNS原理及配置