Tree Traversal Inorder traversal: A/B*C*D+E (LVR)

Slides:



Advertisements
Similar presentations
Divide-and-Conquer. 什麼是 divide-and-conquer ? Divide 就是把問題分割 Conquer 則是把答案結合起來.
Advertisements

Chapter 10 馬可夫鏈 緒言 如果讀者仔細觀察日常生活中所發生的 諸多事件,必然會發現有些事件的未來 發展或演變與該事件現階段的狀況全然 無關,這種事件稱為獨立試行過程 (process of independent trials) ;而另一些 事件則會受到該事件現階段的狀況影響。
布林代數的應用--- 全及項(最小項)和全或項(最大項)展開式
1 Q10276: Hanoi Tower Troubles Again! 星級 : ★★★ 題組: Online-judge.uva.es PROBLEM SET Volume CII 題號: Q10276: Hanoi Tower Troubles Again! 解題者:薛祖淵 解題日期: 2006.
Instructor: Ching-Chi Lin 林清池 助理教授
授課教授:李錫智 Data Structures -2 nd exam-. 1.[15] A simple way for implementing the vector ADT is to use an array A, where A[i] stores the element at rank.
1.1 線性方程式系統簡介 1.2 高斯消去法與高斯-喬登消去法 1.3 線性方程式系統的應用(-Skip-)
Graph V(G 1 )={0, 1, 2, 3, 4, 5, 6, 7, 8, 9} E(G 1 )={(0, 2), (0, 3), (1, 4), (2, 3), (2, 5), (2, 6), (3, 6), (3, 7), (4, 7), (5, 6), (5,
JAVA 程式設計與資料結構 第十四章 Linked List. Introduction Linked List 的結構就是將物件排成一列, 有點像是 Array ,但是我們卻無法直接經 由 index 得到其中的物件 在 Linked List 中,每一個點我們稱之為 node ,第一個 node.
8.1 何謂高度平衡二元搜尋樹 8.2 高度平衡二元搜尋樹的加入 8.3 高度平衡二元搜尋樹的刪除
: The Playboy Chimp ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10611: The Playboy Chimp 解題者:蔡昇宇 解題日期: 2010 年 2 月 28 日 題意:給一已排序的數列 S( 升冪.
具備人臉追蹤與辨識功能的一個 智慧型數位監視系統 系統架構 在巡邏模式中 ,攝影機會左右來回巡視,並 利用動態膚色偵測得知是否有移動膚色物體, 若有移動的膚色物體則進入到追蹤模式,反之 則繼續巡視。
: Walking on a Grid ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10913: Walking on a Grid 解題者:陳盈村 解題日期: 2008 年 5 月 2 日 題意:給定一個 N*N 矩陣,題目要求依照.
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
:Problem D: Bit-wise Sequence ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10232: Problem D: Bit-wise Sequence 解題者:李濟宇 解題日期: 2006 年 4 月 16.
24-6 設定開始與結束場景中的 程式 最後我們要替這個遊戲收個尾, 幫它把開始 的等待畫面跟結束畫面處理一下。
: The largest Clique ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11324: The largest Clique 解題者:李重儀 解題日期: 2008 年 11 月 24 日 題意: 簡單來說,給你一個 directed.
Tree Traversal. Traversal Algorithms preorder inorder postorder.
: Point of View in Flatland ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 11037: Point of View in Flatland 解題者:黃士庭 解題日期: 2007 年 5 月 15 日 題意:在座標平面上給三個圓,找一個點使從這.
第三章 自動再裝載運用篇 使用時機:裝載計劃完成時,尚有剩餘空 間的情形,維持已固定計劃而繼續做裝載 最佳化。以支持次日裝載計劃而提前調整 作業模式。 裝載物品設定和裝載容器設定如前兩章介 紹,於此不再重複此動作,直接從裝載計 劃設定開始,直接從系統內定的物品和容 器選取所需.
Chapter 2 Getting Started Insertion Sort: 能有效率地排序小數字的演算法 範例 :
: Problem A : MiniMice ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11411: Problem A : MiniMice 解題者:李重儀 解題日期: 2008 年 9 月 3 日 題意:簡單的說,題目中每一隻老鼠有一個編號.
第十章 再論結構. 指標與結構的關係 /* File name: ex10-1a.c */ #include int main() { struct student { char *name; int score; }; struct student st= {"Brian", 97}; struct.
: Ahoy, Pirates! ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11402: Ahoy, Pirates! 解題者:李重儀 解題日期: 2008 年 8 月 26 日 題意:有一個海盜島有 N 個海盜,他們的編號 (id)
Review of Chapter 5 張啟中. Threaded Binary Tree 利用 Binary Tree 節點中的 0-links ,指向中序的先行 者或後繼者,以方便中序追蹤。 Threading Rules  A 0 RightChild field at node p is.
短缺,盈餘與均衡. 遊戲規則  老師想出售一些學生喜歡的小食。  老師首先講出價錢,有興趣買的請舉手。
Review of Chapter 5 張啟中. Definition of Tree A tree is a finite set of one or more nodes such that A tree is a finite set of one or more nodes such that.
:Nuts for nuts..Nuts for nuts.. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10944:Nuts for nuts.. 解題者:楊家豪 解題日期: 2006 年 2 月 題意: 給定兩個正整數 x,y.
Marble on tree ★★★☆☆ 題組: ACM Programming Contest World Finals, 1998 題號: Marble on tree 解題者:呂為萱 解題日期: 2011 年 3 月 16 日 題意: 有 n 個箱子,被擺放在 rooted.
資料結構實習-一 參數傳遞.
1 第 4 章 複 因 子 的 應 用複 因 子 的 應 用. 2 移動等額系列 並非 所謂移動系列,是指現值所在的時 間點並非 t = 0. 向 “0” 的左方移動或向 t = “0” 的右 方移動.
4 堆疊與佇列 4.1 前言 四種基本的資料結構 (可儲存資料的容器) 陣列 (Array)、串列(List): 最基本
: Problem G e-Coins ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10306: Problem G e-Coins 解題者:陳瀅文 解題日期: 2006 年 5 月 2 日 題意:給定一個正整數 S (0
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
資料結構實習-二.
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
Review of Chapter 9 張啟中. Inheritance Hierarchy Min PQ Max PQ Min Heap Mergeable Min PQ DeapMin-Max Min-LeftistMin-SkewMinFHeap MinBHeap DEPQMax Heap Symmetric.
資料結構實習-十 Binary Tree Traversal.
Chapter 10 m-way 搜尋樹與B-Tree
2 期末程式第一份報告 報告內容 撰寫此程式的動機和目的以及預期達到的功能和結果 流程圖 繼承關係 資料結構 檔案上傳格式 第 n 組程式流程圖.doc 組別於近日內公告 5/31, 17:00 前交.
中序轉後序 藉由由左向右掃瞄中序運算式產生後序運算式,遇到 運算元就直接輸出,遇到運算符號則先存入堆疊,將 優先權較高者輸出。 範例: a + b * c TokenStack [0] [1] [2] topoutput aa ++0a b+0ab *+ *1ab c+ *1abc eosabc*+
: Problem E Antimatter Ray Clearcutting ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11008: Problem E Antimatter Ray Clearcutting 解題者:林王智瑞.
資料結構實習-六.
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2008.
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 參 資料蒐集的方法.
11 Ch05 遞迴 淡江大學 周清江 1. 2  遞迴函數乃是一個自己反覆呼叫自己的函數  一個典型的遞迴演算法 n! = n * (n-1)! = n * (n-1) * (n-2)! = n * (n-1) * (n-2) * (n-3)! = … = n * (n-1) * (n-2)
: SAM I AM ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11419: SAM I AM 解題者:李重儀 解題日期: 2008 年 9 月 11 日 題意: 簡單的說,就是一個長方形的廟裡面有敵人,然 後可以橫的方向開砲或縱向開砲,每次開砲可以.
:Count the Trees ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10007:Count the Trees 解題者:楊家豪 解題日期: 2006 年 3 月 題意: 給 n 個點, 每一個點有自己的 Label,
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
:Rings and Glue ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10301: Rings and Glue 解題者:施博修 解題日期: 2011 年 5 月 18 日 題意:小約翰有了個大麻煩,他不小心將 rings.
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2009.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Trees --Part I Lai Ah Fur. definition  A tree can be defined recursively as the following: –An empty structure is an empty tree –If t 1,…,t k are disjoint.
Binary Trees In computer science, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left.
Data Structures -3 rd test- 2015/06/01 授課教授:李錫智. Question 1 Suppose we use an array to implement a sorted list. Please answer the following questions.
Discrete Mathematics Chapter-10 Trees. Introduction to Tree (§10.1)  Def 1. A connected (undirected) graph that contains no simple circuits is called.
1 Chapter 13 Priority Queues. 2 Chap.13 Contents 13.1 Introduction 13.2 The PurePriorityQueue Interface 13.3 Implementations of the PurePriorityQueue.
Discrete Mathematics Chapter-10 Trees.
§3 Binary Tree Traversals —— visit each node exactly once L ::= move left ; R ::= move right ; V ::= visit the node. We will always traverse the left.
Data Structures -3 rd exam- 授課教師 : 李錫智 教授. 1.[10] Please answer the following questions about queue: [ 2] What is the response of the statement: “(new.
Group 2 Block 胡貴蓉 Project 2 JMVC code tracing.
 آشنايي با درخت  درخت هاي دودويي  پيمايش درختان  هرم  جنگل اهداف 1.
Activity Networks AOV 網路 AOE 網路. AOV 網路 (Activity on Vertx Networks)  為了表示一件工作中,各子工程間的先後 關係,我們可以利用有向圖中的有向邊代 表事情進行的順序,位於一條有向邊終點 的事件必須要等待起點的事情完成後,才 可以進行。
Traversal From CSCE 3110 Data Structures & Algorithm Analysis
Binary Tree Traversal Methods
Binary Tree Traversal Methods
Binary Tree Traversal Methods
Binary Tree Traversal Methods
Binary Tree Traversal.
6.1.3 Graph representation.
Presentation transcript:

Tree Traversal Inorder traversal: A/B*C*D+E (LVR) Infix form Preorder traversal: +**/ABCDE (VLR) Prefix form Postorder traversal: AB/C*D*E+ (LRV) Postfix form + * E D C / B A 1 2 17 3 14 18 19 4 11 15 16 5 8 12 13 6 7 9 10

Inorder Traversal Informally, inorder traversal calls for moving down the tree toward the left until you can go no farther. (非正式地講法,中序向左移動,一直到達一個空節點為止) Then you “visit” the node, move one node to the right and continue. (然後“拜訪”此空節點的父節點,並且由它的右子節點繼續尋訪) If you can not move to the right, go back one more node. (如果不能向右移動,由上一階層中最後一個未被拜訪的節點繼續尋訪)

Inorder traversal of a binary tree void inorder (tree_pointer ptr) { /* inorder tree traversal */ if (ptr) { inorder (ptrleft_child); printf (“%d”, ptrdata); inorder (ptrright_child); } }

Preorder and Postorder traversals of a binary tree void preorder (tree_pointer ptr) { /* preorder tree traversal */ if (ptr) { printf (“%d”, ptrdata); printf (ptrleft_child); printf (ptrright_child); } } void postorder (tree_pointer ptr) { /* postorder tree traversal */ if (ptr) { postorder(ptrleft_child); postorder(ptrright_child); printf (“%d”,ptrdata); } }

Level-Order Traversal The steps of level-order traversal are: visit the root first (首先拜訪根節點) then the root’s left child followed by the right child (而後是根節點的左子節點,接著根節點的右子節點) visit next level from leftmost node to right most node (以相同的方式拜訪下一階層中的節點,由最左邊的節點到最右邊的節點 )

An example for level-order Traversal + * E D C / B A 1 2 4 6 8 9 7 5 3 Level-order traversal: +*E*D/CAB

Level-order traversal of a binary tree void level_order (tree_pointer ptr) { /* level order tree traversal */ int front = near = 0; tree_pointer queue [MAX_QUEUE_SIZE]; if (!ptr) return; /* empty tree */ addq(ptr); for (;;) { ptr = deleteq(); if (ptr) { printf(“%d”, ptrdata); if (ptrleftChild) addq(ptrleft_child); if (ptrrightChild) addq(ptrright_child); } else break; } }

練習一 You are required to implement a binary tree abstract data type.               練習一          You are required to implement a binary tree abstract data type. The  functions of the ADT include Gen_BinTree, Pre_traversal , In_traversal , Post_traversal and Level_traversal.  The input is a 3-tuple list as follows (-, (/, (*, 16, (+, 24, 13)), 9), 10). The Gen_BinTree function will transfer the 3-tuple list to a binary tree structure as Fig 1. The Pre_traversal function will perform the preorder traversal of the binary tree. The In_traversal function will perform the inorder traversal of the binary tree. 8

              練習一          The Post_traversal function will perform the postorder traversal of the binary tree. The Level_traversal function will perform the level-order traversal of the binary tree. The program should be written in C language. The output will left for you to decide. * - / 16 + 9 10 24 13 Fig 1 9

繳交日期 程式demo: 5/20(三) 於實習課