数据结构 二叉树的存储结构
线程二叉树 (Threaded Binary Tree )
A binary tree can be represented by using array representation or linked list representation. When a binary tree is represented using linked list representation. If any node is not having a child we use a NULL pointer. These special pointers are threaded and the binary tree having such pointers is called a threaded binary tree. Thread in a binary tree is represented by a dotted line. In linked list representation of a binary tree, they are a number of a NULL pointer than actual pointers. This NULL pointer does not play any role except indicating there is no child. The threaded binary tree is proposed by A.J Perlis and C Thornton. There are three ways to thread a binary tree.
可以通过使用数组表示形式或链接列表表示形式来表示二叉树 。 当使用链接列表表示形式表示二叉树时。 如果任何节点没有子节点,我们将使用NULL指针。 这些特殊的指针是线程化的,具有此类指针的二进制树称为线程化的二进制树。 二叉树中的线程用虚线表示。 在二叉树的链表表示中,它们是空指针的数量,而不是实际指针的数量。 该NULL指针除指示没有子代外没有任何作用。 线程二叉树由AJ Perlis和C Thornton提出。 线程二叉树的方法有三种。
In the in order traversal When The right NULL pointer of each leaf node can be replaced by a thread to the successor of that node then it is called a right thread, and the resultant tree called a right threaded tree or right threaded binary tree.
在顺序遍历中,如果每个叶节点的Right NULL指针都可以由指向该节点后继节点的线程替换,则它称为右线程,而生成的树称为右线程树或右线程二叉树。
When The left NULL pointer of each node can be replaced by a thread to the predecessor of that node under in order traversal it is called left thread and the resultant tree will call a left threaded tree.
当每个节点的Left NULL指针可以按顺序遍历到该节点的前任对象的线程时,称为左线程,结果树将称为左线程树。
In the in order traversal, the left and the right NULL pointer can be used to point to predecessor and successor of that node respectively. then the resultant tree is called a fully threaded tree.
在顺序遍历中,可以使用左侧和右侧的NULL指针分别指向该节点的前任和后任。 那么生成的树称为全线程树。
In the threaded binary tree when there is only one thread is used then it is called as one way threaded tree and when both the threads are used then it is called the two way threaded tree. The pointer point to the root node when If there is no in-order predecessor or in-order successor.
在线程二叉树中,当仅使用一个线程时,则将其称为单向线程树,而当同时使用两个线程时,则将其称为双向线程树。 如果不存在有序的前任或有序的后任,则指针指向根节点。
Consider the following binary tree:
考虑以下二进制树:
The in-order traversal of a given tree is D B H E A F C G. Right threaded binary tree for a given tree is shown below:
给定树的有序遍历为DBHEAFCG 。 给定树的右线程二叉树如下所示:
线程二叉树的优点 (Advantages of Thread Binary Tree)
Non-recursive pre-order, in-order and post-order traversal can be implemented without a stack.
无需堆栈即可实现非递归的有序遍历,有序遍历和后遍历遍历。
线程二叉树的缺点 (Disadvantages of Thread Binary Tree)
Insertion and deletion operation becomes more difficult.
插入和删除操作变得更加困难。
Tree traversal algorithm becomes difficult.
树遍历算法变得困难。
Memory required to store a node increases. Each node has to store the information whether the links is normal links or threaded links.
存储节点所需的内存增加。 无论链接是普通链接还是线程链接,每个节点都必须存储信息。
二叉树的线程类型 (Types of Threaded of Binary Tree)
There are three types of Threaded Binary Tree,
线程二叉树有三种类型,
1) Right Threaded Binary Tree
1)右线程二叉树
Right threaded binary tree for a given tree is shown:
显示给定树的右线程二叉树:
2) Left Threaded Binary Tree
2)左线程二叉树
Left threaded binary tree for a given tree is shown:
显示给定树的左线程二叉树:
3) Fully Threaded Binary Tree
3)全线程二叉树
Fully threaded binary tree for a given tree is shown:
显示给定树的全线程二叉树:
翻译自: https://www.includehelp.com/data-structure-tutorial/threaded-binary-tree.aspx
数据结构 二叉树的存储结构