數據結構 二叉樹的存儲結構
線程二叉樹 (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
數據結構 二叉樹的存儲結構