題組內容

題組 05-06:下表示某一位學生紀錄的 IP 位址,請從正確的 IP 位址中,回答 05-06 題。

01.有一個二元樹(binary tree),其節點中序走訪(inorder traversal)為BGADFCE,前序走 訪(preorder traversal)為DABGEFC,則其後序走訪(postorder traversal)應為 (1) 。

詳解 (共 3 筆)

古佳怡
古佳怡
詳解 #1761320
2016/06/09
Inorder:(left subtree) root (right subtree)
Preorder:root (left subtree) (right subtree)
Postorder:(left subtree) (right subtree) root

1. 由Preorder可推出D為root
2. 由D為root,可再由Inorder推出BGA為left subtree、FCE為right subtree
3. 重覆以上動作,直到沒有subtree為止
=>推出tree為(DAEB##G##F##C##)
tree格式參考:https://leetcode.com/discuss/528/format-of-oj-binary-trees

最後可得Postorder為GBACFED

徐逸娟
徐逸娟
詳解 #3040330
2018/10/20
GBACFED
sofi1030
sofi1030
詳解 #1755516
2016/05/10
DGBACFE