數據結構 二叉樹的存儲結構_線程二叉樹| 數據結構

數據結構 二叉樹的存儲結構

線程二叉樹 (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提出。 線程二叉樹的方法有三種。

  1. 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指針都可以由指向該節點后繼節點的線程替換,則它稱為右線程,而生成的樹稱為右線程樹或右線程二叉樹。

  2. 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指針可以按順序遍歷到該節點的前任對象的線程時,稱為左線程,結果樹將稱為左線程樹。

  3. 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:

考慮以下二進制樹:

Threaded Binary Tree 1

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)

  1. Insertion and deletion operation becomes more difficult.

    插入和刪除操作變得更加困難。

  2. Tree traversal algorithm becomes difficult.

    樹遍歷算法變得困難。

  3. 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:

顯示給定樹的右線程二叉樹:

Right Threaded Binary Tree

2) Left Threaded Binary Tree

2)左線程二叉樹

Left threaded binary tree for a given tree is shown:

顯示給定樹的左線程二叉樹:

Left Threaded Binary Tree

3) Fully Threaded Binary Tree

3)全線程二叉樹

Fully threaded binary tree for a given tree is shown:

顯示給定樹的全線程二叉樹:

Fully Threaded Binary Tree

翻譯自: https://www.includehelp.com/data-structure-tutorial/threaded-binary-tree.aspx

數據結構 二叉樹的存儲結構

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378438.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378438.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378438.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

七、有機硅柔軟劑在不同發展階段分子結構特征及主要解決的問題?

有機硅柔軟劑在不同發展階段分子結構特征及主要解決的問題? 收集資料階段 聚有機硅氧烷具有低表面能、優良的潤滑性、熱穩定性和疏水性。從分子層面分析,經聚有機硅氧烷處理的織物,其柔軟性來自硅氧烷骨架中 Si—O—Si鍵的 360自由旋轉及甲基之間的低相互作用。因此,聚有機…

【智能車Code review】——拐點的尋找

博主聯系方式: QQ:1540984562 QQ交流群:892023501 群里會有往屆的smarters和電賽選手,群里也會不時分享一些有用的資料,有問題可以在群里多問問。 系列文章 【智能車Code review】—曲率計算、最小二乘法擬合 【智能車Code review】——坡道圖像與控制處理 【智能車Code re…

linux 單例模式改密碼,Java 利用枚舉實現單例模式

引言單例模式比較常見的實現方法有懶漢模式,DCL模式公有靜態成員等,從Java 1.5版本起,單元素枚舉實現單例模式成為最佳的方法。Java枚舉基本用法枚舉的用法比較多,本文主要旨在介紹利用枚舉實現單例模式的原理,所以這里…

編碼簡介

編碼簡介最近被字符集搞得頭大,基于為自己掃盲的目的,索性收集資料研究一下,現將各方資料歸納成本文。這里并不想把復雜的規則說明一大通。如有需要,請參照其他資料或本文給出的參考資料。 如有錯誤,歡迎指正。…

2013年5月7日---JS中的正則

/*(1)RegExp對象的test方法------------------C#中的isMatchvar num1d23; //一個字符串var regnew RegExp(^\\d$); //準備正則alert(reg.test(num)); //開始匹配并彈出--false*//*(2)ReExp對象的test方法var num123;var regnew RegExp(/^\d$/);ale…

八、關于防水透濕整理

1,防水透濕整理加工技術的類型? 收集資料階段 按照加工方式分類 防水透濕織物按照加工方式可分為高密織物、涂層織物和層壓織物。不同加工方式所對應的織物各有特色。高密織物產生于 20 世紀 80 年代,它的密度可達到普通織物的 20 倍。在晴朗天氣時,紗線孔隙大約為 10 μm…

linux qt 音頻文件怎么打開,Qt:獲取Linux中可用音頻設備的列表

我想要獲取我的Linux系統上可用的所有音頻設備的列表。然后我會將這個列表顯示在一個組合框中,用戶將從中選擇用于錄制/播放的設備。根據用戶的選擇,我將構建QAudioInput和QAudioOutput進行錄制/播放。Qt:獲取Linux中可用音頻設備的列表根據Q…

c# uri.host_C#| Uri.GetLeftPart()方法與示例

c# uri.hostUri.GetLeftPart()方法 (Uri.GetLeftPart() Method) Uri.GetLeftPart() method is an instance method that is used to get a specified part from the given URI based on passed UriPartial enum. Uri.GetLeftPart()方法是一個實例方法,用于基于傳遞的…

求質數算法的N種境界 (N 10) zz

★引子 前天,俺在《俺的招聘經驗[4]:通過筆試答題能看出啥?》一文,以"求質數"作為例子,介紹了一些考察應聘者的經驗。由于本文沒有政治敏感內容,順便就轉貼到俺在CSDN的鏡像博客。   昨天&…

【智能車Code review】——小S與中S道路判斷

博主聯系方式: QQ:1540984562 QQ交流群:892023501 群里會有往屆的smarters和電賽選手,群里也會不時分享一些有用的資料,有問題可以在群里多問問。 系列文章 【智能車Code review】—曲率計算、最小二乘法擬合 【智能車Code review】——坡道圖像與控制處理 【智能車Code re…

Python匿名函數---排序

一、列表的排序 nums [1,2,3,5,4,7,87,4,9,56,44,7,5] nums.sort()#默認從小到大排序 nums#結果為:[1, 2, 3, 4, 4, 5, 5, 7, 7, 9, 44, 56, 87]nums [1,2,3,5,4,7,87,4,9,56,44,7,5] nums.sort(reverseTrue)#從大到小排序 nums#結果為:[87, 56, 44, …

linux 內核編譯需要多大空間,編譯2.6.28內核出錯。。。。空間不足。而/tmp/還有好幾G...

編譯2.6.28內核出錯。。。。空間不足。而/tmp/還有好幾G發布時間:2009-01-02 16:56:47來源:紅聯作者:weixq316今天閑來無事,就去下載了最新的內核--2.6.28來編譯安裝。。。:0)1放在/usr/src/2.6.28/中編譯。。。。。我的/usr還有1G多的空間。…

如何用vi 復制第5行到第10行并粘貼到第12行之后

方法一: 光標放到第五行,輸入:y6y光標放到第12行,輸入:p方法二:命令行模式下輸入:5,10 co 12方法三:延伸一下, 有時候不想費勁看多少行或復制大量行時,可以使用標簽來替代光標移到起…

go zap去除程序名稱_適用于Zip,Zap和Zoom游戲的Python程序

go zap去除程序名稱Write a python program that displays a message as follows for a given number: 編寫一個python程序,顯示給定數字的消息如下: If it is a multiple of three, display "Zip". 如果是三的倍數,則顯示“ Zip…

【智能車Code review】——環島的判定與補線操作

博主聯系方式: QQ:1540984562 QQ交流群:892023501 群里會有往屆的smarters和電賽選手,群里也會不時分享一些有用的資料,有問題可以在群里多問問。 視頻講解 這里是對于代碼的講解視頻,大約一個小時,需要的同學可以看看:B站:meeting_01 系列文章 【智能車Code review】…

Python交換兩個變量的三種方法

一、借助于第三個變量(很常用) a 5 b 6c 0 c a a b b c print("a%d,b%d"%(a,b))#結果為:a6,b5二、如何不借助第三個變量實現兩個變量交換數據呢? a 5 b 6a ab b a-b a a-b print("a%d,b%d"%(a,b))#結果為:a…

linux下怎么查kill某個進程,Linux下查詢進程PS或者殺死進程kill的小技巧

假設我們要kill掉tomcat:那么我們首先需要tomcat的進程號pid:ps -aux | grep tomcat記下tomcat的PID后,執行:kill PID(tomcat)好了,就到這里....路人甲:小的們,滅了這個欺騙人民情感的家伙&…

【筆記】VB控件MSComm功能介紹

VB中的MSComm 控件通過串行端口傳輸和接收數據,為應用程序提供串行通訊功能。MSComm控件在串口編程時非常方便,程序員不必去花時間去了解較為復雜的API函數,而且在VC、VB、Delphi等語言中均可使用。 Microsoft Communications Control&#x…

string charat_Java String charAt()方法與示例

string charat字符串charAt()方法 (String charAt() Method) charAt() method is a String class method in Java, it is used to get the character from specified index from a given string. charAt()方法是Java中的String類方法,用于從給定字符串的指定索引中獲…

opencv模板匹配

matchTemplate函數參數 模板匹配是通過模板在采集到的原圖像進行滑動尋找與模板圖像相似的目標。模板匹配不是基于直方圖的方式,而是基于圖像的灰度匹配。 6種匹配度量方法: 平方差匹配法CV_TM_SQDIFF 歸一化平方差匹配法CV_TM_SQDIFF_NORMED 相關匹配…