《数据结构》课程教学资源(PPT讲稿)二叉树和二叉搜索树 Trees, Binary Trees, and Binary Search Trees

Trees, Binary Trees and Binary Search Trees
Trees, Binary Trees, and Binary Search Trees

Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations(search insert, delete) is o(log N)? Trees Basic concepts Tree traversal Binary tree Binary search tree and its operations
2 Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search, insert, delete) is O(log N)? Trees Basic concepts Tree traversal Binary tree Binary search tree and its operations

Tr ees a tree T is a collection of nodes T can be empty (recursive definition) If not empty, a tree T consists of c a(distinguished)node r( the root B and zero or more nonempty sub-trees T1, T2, .. Tk root T1 T T3 T4 T Figure 4.1 Generic tree
3 Trees A tree T is a collection of nodes T can be empty (recursive definition) If not empty, a tree T consists of a (distinguished) node r (the root), and zero or more nonempty sub-trees T1 , T2 , ...., Tk

Tree can be viewed as a nested lists list of lists of lists Tree is also a graph
4 Tree can be viewed as a ‘nested’ lists: list of lists of lists … Tree is also a graph …

Some terminologies Figure 4.2 A tree Child and Parent Every node except the root has one parent a node can have a zero or more children Leaves Leaves are nodes with no children Sibling nodes with same parent
5 Some Terminologies Child and Parent Every node except the root has one parent A node can have a zero or more children Leaves Leaves are nodes with no children Sibling nodes with same parent

6 More Terminologies Path A sequence of edges Length of a path number of edges on the path Depth of a node length of the unique path from the root to that node Height of a node length of the longest path from that node to a leaf all leaves are at height 0 The height of a tree= the height of the root the depth of the deepest leaf Ancestor and descendant If there is a path from n1 to n2 Proper ancestor and proper descendant of n1 n1 is an ancestor of n2. n2 is a descendant
6 More Terminologies Path A sequence of edges Length of a path number of edges on the path Depth of a node length of the unique path from the root to that node Height of a node length of the longest path from that node to a leaf all leaves are at height 0 The height of a tree = the height of the root = the depth of the deepest leaf Ancestor and descendant If there is a path from n1 to n2 n1 is an ancestor of n2, n2 is a descendant of n1 Proper ancestor and proper descendant

Example: UNIX Directory fuss mark* alex* bill* book course junk junk work* course+ chI.r ch2. r ch3. r cop3530* cop3212 fal198* spr99* sum99* fa!98* fa99米 yl.T syl. r grades progl r prog2 r prog2 r progl r grades Figure 4.5 UNIX directory
7 Example: UNIX Directory

Tree Operations Traversal, the most important we will not implement a general tree, so wont discuss Search Insertion Deletion
8 Tree Operations Traversal, the most important we will not implement a general ‘tree’, so wont discuss Search Insertion Deletion

Tree Traversal Used to print out the data in a tree in a certain order Pre-order traversal Print the data at the root Recursively print out all data in the leftmost subtree Recursively print out all data in the rightmost subtree
9 Tree Traversal Used to print out the data in a tree in a certain order Pre-order traversal Print the data at the root Recursively print out all data in the leftmost subtree … Recursively print out all data in the rightmost subtree

A drawing of tree with two pointers Struct TreeNode i double elementi // the data TreeNode* child; / FIRST child go to the next generation TreeNode* next;// next SIBLING: go to the same generation
10 A drawing of tree with two pointers … Struct TreeNode { double element; // the data TreeNode* child; // FIRST child : go to the next generation TreeNode* next; // next SIBLING : go to the same generation }
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- Robust Networking Architecture and Secure Communication Scheme for Heterogeneous Wireless Sensor Networks.pptx
- 中国科学技术大学:《算法基础》课程教学资源(PPT课件讲稿)第五讲 概率分析与随机算法.pptx
- 同济大学:《大数据分析与数据挖掘 Big Data Analysis and Mining》课程教学资源(PPT课件讲稿)Data Preprocessing.ppt
- 《编译原理与技术》课程教学资源(PPT课件讲稿)运行环境.ppt
- 华南理工大学:神经计算的生理和动力学指标(PPT讲稿).ppt
- 中国科学技术大学:《嵌入式操作系统 Embedded Operating Systems》课程教学资源(PPT课件讲稿)第七讲 存储器管理.ppt
- 中国科学技术大学:《网络信息安全 NETWORK SECURITY》课程教学资源(PPT课件讲稿)Windows 操作系统.ppt
- 《Java面向对象程序设计》课程教学资源(PPT课件讲稿)第四章 Java图形用户界面设计 4.3 事件处理.pptx
- 南京航空航天大学:《C++》课程电子教案(PPT课件讲稿)第2章 文件操作.pptx
- MSC Software Corporation:Dynamic System Modeling, Simulation, and Analysis Using MSC.EASY5(Introductory Class).ppt
- 南京大学:《面向对象技术 OOT》课程教学资源(PPT课件讲稿)构件化软件 Component Software.ppt
- 新乡学院:《PHP动态网站开发》课程教学资源(教学大纲).pdf
- 《Android 程序设计基础》课程教学资源(PPT课件讲稿)第8章 数据存储和访问.ppt
- 《高级软件工程》课程教学大纲 Advanced Software Engineering.doc
- 南京大学:《计算机图形学》课程教学资源(PPT课件讲稿)第6讲 图形观察与几何变换.pptx
- 《数据结构》课程教学资源(PPT课件讲稿)第六章 树与二叉树.ppt
- 烟台大学:《C语言程序设计》课程电子教案(PPT课件讲稿)第五章 数组、字符串、指针(主讲:荆蕾).ppt
- 《模式识别》课程教学资源(PPT讲稿)Learning with information of features.ppt
- 合肥工业大学:使用大数据进行计算建模(PPT讲稿)Computing/Modeling with Big Data(主讲:吴信东).pptx
- 人工神经网络(ANN)方法简介(PPT课件讲稿).ppt
- 《网页设计与制作》课程PPT教学课件(Fireworks Mx 2004)第九章 Firework图像处理.ppt
- 西安交通大学:《微机原理与接口技术》课程教学资源(PPT课件讲稿)第4章 存储器系统接口.ppt
- 《计算机网络基础》课程PPT教学课件(讲稿)第4章 IP协议.ppt
- 大连理工大学:《计算机网络》课程教学资源(PPT课件讲稿)Chapter 1 Introduction(roadmap,主讲:孙伟峰).ppt
- 《数据库系统概论》课程教学资源(PPT课件讲稿)数据结构实用教程(共十章).ppt
- 上海交通大学:《程序设计》课程教学资源(PPT课件讲稿)第7章 间接访问——指针.ppt
- 编译程序构造 COMPILER CONSTRUCTION(PPT讲稿)原理与实践 Principles and Practice.ppt
- 《3ds Max 9》教学资源(PPT课件)第8章 灯光、摄影机、渲染输出.ppt
- 《运筹学与最优化方法》课程教学资源(PPT课件讲稿)第十章 智能优化计算简介.ppt
- 东北大学:《可信计算基础》课程教学资源(PPT课件讲稿)第五讲 分布式系统的安全(主讲:周福才).ppt
- 《电脑组装与维护实例教程》教学资源(PPT课件讲稿)第14章 系统的维护.ppt
- 《PHP程序设计》教学资源(PPT课件讲稿)项目七 Ajax商品发布.ppt
- 《计算机网络》课程教学资源(PPT课件讲稿)第六章 传输层.ppt
- 《计算机系统安全》课程PPT教学课件(信息安全与管理)第九章 防火墙.ppt
- 同济大学:《大数据分析与数据挖掘 Big Data Analysis and Mining》课程教学资源(PPT课件讲稿)Getting to Know Your Data.ppt
- 香港浸会大学:Computer Security(PPT课件讲稿)Cryptography Chapter 1 Symmetric Ciphers.ppt
- 《计算机文化基础》课程教学资源(PPT课件讲稿)第九章 多媒体技术基础.ppt
- 数据挖掘10大算法产生过程(PPT讲稿).ppt
- 清华大学:高校信息化建设理论与规划(PPT讲稿).ppt
- 《汇编语言程序设计》课程教学资源(PPT课件讲稿)第二章 IBM-PC微机的功能结构.ppt