コンテンツにスキップ

木構造 (データ構造)

出典: フリー百科事典『ウィキペディア(Wikipedia)』
親子構造

木構造(きこうぞう)とは、グラフ理論におけるに対応づけられるデータ構造である。

用語[編集]


使

使[ 1]

0 (: child node)  (: parent node)  (: sibling node)  (: descendant node)  (: ancestor node) 1

 (: root node) 11辿

 (: leaf node) 

 (: internal nodeinner node) 

 (: height) 

 (: depth)  0 

 (: subtree)  T T (: proper subtree) 

 (: forest) 

[]


 (: ordered tree) 2

[]












使

[]

: F, B, A, D, C, E, G, I, H
: A, B, C, D, E, F, G, H, I
: A, C, E, D, B, H, I, G, F
: F, B, G, A, D, I, C, E, H

 (: traverse) 調1

[]


調調3

 (: pre-order)


(一)調

(二)

(三)

2

 (: in-order)


(一)

(二)調

(三)

2使

 (: post-order)


(一)

(二)

(三)調

[]


 (: level-order)


[]

2分探索木 この2分探索木において、
  • 前順走査での調査順: F, B, A, D, C, E, G, I, H
  • 間順走査での調査順: A, B, C, D, E, F, G, H, I
    • 2分探索木での間順走査は、ソートされた順となる。
  • 後順走査での調査順: A, C, E, D, B, H, I, G, F
  • レベル順走査での調査順: F, B, G, A, D, I, C, E, H

擬似コード[編集]

前順(n)
    n を処理
    for each (n の子ノード i)
        前順(i)
間順(n)
    if (n に左の子ノードがあれば)
        間順(n の左の子ノード)
    n を処理
    if (n に右の子ノードがあれば)
        間順(n の右の子ノード)
後順(n)
    for each (n の子ノード i)
        後順(i)
    n を処理

使


レベル順(n)
    n をキューに追加
    while (キューに要素を含むなら)
        n ← キューから取り出すnを処理
        for each (nの子ノードi)
            i をキューに追加

2[]

2

2 (: threaded binary tree) 使Joseph M. Morris 1979[1]2使使

2
Sub inorder(n∈node)
    Do While hasLeftChild(n)
        Let node ← node.left
    Loop
    Do
        visit(n)
        If hasRightChild(n) Then
            Let n ← n.right
            Do While hasLeftChild(n)
                Let n ← n.left
            Loop
        Else
            Let n ← n.right
        End If
    Loop While n ≠ Null
End Sub

[]















[]



 - 2
2

 - 3




 - 
2 - 2
AA

AVL22



2

T (T-tree)

 (splay tree)

Treap


B (B-tree)
B+B*

2-32-3-4








 - 




 (Suffix tree)


 (range tree)

 (segment tree)

 (interval tree)

R (Rectangle tree)

kd

[]


使

XML DOM

 

使

[]

注釈[編集]

  1. ^ 一般に無向木は、それに含まれる任意のノードを根として解釈可能な非根付き木である。有向木は、エッジが、葉から根に向かう向きの場合と、根から葉に向う向きの場合があるが、いずれにしても根となるノードが決められた根付き木となる。

出典[編集]

  1. ^ Morris, Joseph M. (December 1979). “Traversing binary trees simply and cheaply”. Information Processing Letters 9 (5): 197-200. doi:10.1016/0020-0190(79)90068-1. 

関連項目[編集]

参考文献[編集]

  • Donald Knuth. The Art of Computer Programming: Fundamental Algorithms, Third Edition. Addison-Wesley, 1997. ISBN 0-201-89683-4 . Section 2.3: Trees, pp.308–423.
  • Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7 . Section 10.4: Representing rooted trees, pp.214–217. Chapters 12–14 (Binary Search Trees, Red-Black Trees, Augmenting Data Structures), pp.253–320.
  • Dale, Nell. Lilly, Susan D. "Pascal Plus Data Structures". D. C. Heath and Company. Lexington, MA. 1995. Fourth Edition.
  • Drozdek, Adam. "Data Structures and Algorithms in C++". Brook/Cole. Pacific Grove, CA. 2001. Second edition.

外部リンク[編集]