Practical Examples
Through practical example, I am going to explain how to utilize query to find related nodes in hierarchical data.
Practical Example for Finding Ancestor Nodes
Finding ancestor nodes is used for "breadcrumbs list" seen often on a web site.
[Top Page] |--[Products] | |--[Smart Phone Apps] | +--[Desktop Apps] |--[News] | |--[2015/10] | |--[2015/09] | |--[2015/08] | +--[2015/07] +--[About Us] |--[Corporate Philosophy] |--[Access] +--[Contact Us]
When view the page of "Corporate Philosophy" on the web site such map as figure above, breadcrumb list is put to the top of the page.
Transition diagram of all the pages in website of example is considered the tree structure. Top page means root node. If can find ancestor nodes of "Corporate Philosophy", can create the breadcrumb list.
Practical Example for Finding Subtree Nodes
Tree BBS has the function to reply to the specified comment. When consider all comments as nodes, the stored data has hierarchical structure. When view the "Comment of flow" in the tree BBS, we use to find subtree nodes.
[2015/03/31] |--[Let's Party tonight! (John)] | |--[I will join! (Mike)] | | +--[Thanks! (John)] | |--[Can not join tonight. (Anne)] | | +--[When OK? (John)] | +--[OK, but 2 hours only. (Tom)] | |--[Me too. (Eucen)] | +--[I see! (John)] +--[I losted my smart phone. (Bill)] |--[When? (Diana)] | +--[Yesterday. (Bill)] +--[Did you check GPS? (Fred)] +--[Yet (Bill)]
As shown in the figure above, there are two of the threads posted on March 31, 2015. To display only the thread of [Let's Party tonight! (John)], it need the function to find the subtree of comment of John.
In the case, can not use the way to find all nodes. Because there is the cost problem for finding nodes in huge data of Tree BBS.