1 / 20

樹狀結構 Trees

樹狀結構 Trees. 樹狀結構之術語 (Terminology). 樹狀結構之定義 (Definition). A tree consists of a node, called its root, and zero or more subtrees, each of which is itself a tree. 樹狀結構之處置程序 ( Traversal ). 前序處置程序 (Preorder traversal) 後序處置程序 (Postorder traversal) 中序處置程序 (Inorder traversal). 先處置樹根

dinesh
Download Presentation

樹狀結構 Trees

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 樹狀結構 Trees

  2. 樹狀結構之術語(Terminology)

  3. 樹狀結構之定義(Definition) A tree consists of a node, called its root, and zero or more subtrees, each of which is itself a tree.

  4. 樹狀結構之處置程序 (Traversal) • 前序處置程序(Preorder traversal) • 後序處置程序(Postorder traversal) • 中序處置程序(Inorder traversal)

  5. 先處置樹根 • 由左而右以前序處置程序處置樹根之下的各個子樹 • 前序處置程序(Preorder traversal)

  6. 由左而右以後序處置程序處置樹根之下的各個子樹由左而右以後序處置程序處置樹根之下的各個子樹 • 處置樹根 • 後序處置程序(Postorder traversal)

  7. 以中序處置程序先處置樹根之下的左子樹 • 再處置樹根 • 以中序處置程序處置樹根之下的右子樹 • 中序處置程序(Ineorder traversal)─只適用於二元樹(Binary tree)

  8. 二元樹(Binary tree)之定義 A binary tree is a tree in which each node has at most two children.

  9. 樹狀結構之線性表示法(Linear representations) • 括號表示法(parenthesis notation): A ( B ( E F ) C ( G H I ) D ( J K ))

  10. 樹狀結構之線性表示法(Linear representations) • 層級表示法(level number notation): A1 B2 E3 F3 C2 G3 H3 I3 D2 J3 K3

  11. 樹狀結構之線性表示法(Linear representations) • 子數表示法(children number notation): A3 B2 E0 F0 C3 G0 H0 I0 D2 J0 K0

  12. 先處置樹根 • 由左而右以前序處置程序處置樹根之下的各個子樹 • 前序處置程序(Preorder traversal) A B E C F G D

  13. 由左而右以後序處置程序處置樹根之下的各個子樹由左而右以後序處置程序處置樹根之下的各個子樹 • 處置樹根 • 後序處置程序(Postorder traversal) E B F D G C A

  14. 以中序處置程序先處置樹根之下的左子樹 • 再處置樹根 • 以中序處置程序處置樹根之下的右子樹 • 中序處置程序(Ineorder traversal)─只適用於二元樹(Binary tree) E B A F C G D

  15. 由處置程序推導二元樹 • 已知二元樹之前序處置程序與後序處置程序能否推導?其解是否唯一? • 已知二元樹之前序處置程序與中序處置程序能否推導?其解是否唯一? • 已知二元樹之後序處置程序與中序處置程序能否推導?其解是否唯一?

  16. 前序處置程序A B E C F G D • 中序處置程序E B A F C G D • 已知二元樹之前序處置程序與中序處置程序能否推導?其解是否唯一? 前序:A ( B E C F G D ) 中序:( E B ) A ( F C G D ) 前序:A ( B ( E ) C ( F G D ) ) 中序:( ( E ) B ) A ( ( F ) C ( G D ) ) 前序:A ( B ( E ) C( FG ( D ) ) ) 中序:( ( E ) B )A ( ( F )C(G ( D ) ))

  17. 後序處置程序E B F D G C A • 中序處置程序E B A F C G D • 已知二元樹之後序處置程序與中序處置程序能否推導?其解是否唯一? 後序:( E B F D G C ) A 中序:( E B ) A ( F C G D ) 後序:( ( E ) B ( F D G ) C) A 中序:( ( E ) B) A ( ( F ) C ( G D ) ) 後序:( ( E ) B ( F ( D ) G) C ) A 中序:( ( E ) B ) A ( ( F ) C (G ( D ) ) )

  18. 前序處置程序A B E C F G D • 後序處置程序E B F D G C A • 已知二元樹之前序處置程序與後序處置程序能否推導?其解是否唯一? 前序:A ( B E C F G D ) 後序:( E B F D G C ) A 前序:A ( B ( E ) C ( F G D ) ) 後序:( ( E ) B ( F D G ) C ) A 前序:A ( B ( E ) C ( F G ( D ) ) ) 後序:( ( E ) B ( F ( D ) G ) C ) A

  19. 樹狀結構之應用 • 資料搜尋 • 資料排序 • 資料庫索引 • 家譜 • 組織階層架構 • 迷宮

  20. 樹狀結構之應用 • 組織階層架構

More Related