EvoTalk

Posts Tagged ‘tree

24 五月, 2006

Storing Hierarchical Data in a Database

Posted by: asd In: Web| 程式設計

如何存儲tree structure

兩種方式

The Adjacency List Model
Modified Preorder Tree Traversal

The Adjacency List Model
存儲親子關係,透過recursive方式印出 tree

缺點為缺乏效率,遇到large tree要作多次的recursive call。
Modified Preorder Tree Traversal
每個node多存儲左、右編號,編號順序是依照preorder (中、左、右順序走訪)

Table內記錄,可以沒有parent column

缺點: 較難懂
詳細說明參考 Storing Hierarchical Data in a Database

Tags:

28 四月, 2006

Ternary Search Trees

Posted by: asd In: C++| 科技新知| 程式設計| 網站推薦

Ternary Search Trees結合了binary search trees 及 digital search tries的優點,也就是說具備digital search tries只儲存word list節省空間與binary search tree搜尋快速的特性。適合拿來當作查詢字典的資料結構。實作在此架構的演算法除了exactly match之外,還有Partial-Match Searching & Near-Neighbor Searching。
參考資料:

Ternary Search Trees – Dr. Dobb’s Journal April 1998
Ternary Search Trees -Jon Bentley and Robert Sedgewick
Java : Plant your data in a ternary search tree
Sourceforge -C++ Code Ternary Search Trees

Tags: