A ResearchInData Structures(Trees and Graph)Submittedby:Ryan Paolo SalvadorSubmittedto:Mrs. Elsa SalvadorOctober 9, 2013
Trees and indexesThe tree is one of the most powerful of the advanced data structures and it often pops up in even moreadvanced subjects such as AI and compiler design. Surprisingly though the tree is important in a muchmore basic application - namely the keeping of an efficient index.Whenever you use a database there is a 99% chance that an index is involved somewhere. The simplesttype of index is a sorted listing of the key field. This provides a fast lookup because you can use a binarysearch to locate any item without having to look at each one in turn.The trouble with a simple ordered list only becomes apparent once you start adding new items and haveto keep the list sorted - it can be done reasonably efficiently but it takes some advanced juggling. A moreimportant defect in these days of networking and multi-user systems is related to the file lockingproperties of such an index. Basically if you want to share a linear index and allow more than one user toupdate it then you have to lock the entire index during each update. In other words a linear index isn'teasy to share and this is where trees come in - I suppose you could say that trees are shareable.Tree ecologyA tree is a data structure consisting of nodes organised as a hierarchy - see Figure 1.Tree1Figure 1: Some tree jargonThere is some obvious jargon that relates to trees and some not so obvious both are summarised in theglossary and selected examples are shown in Figure 1.I will try to avoid overly academic definitions or descriptions in what follows but if you need a quickdefinition of any term then look it up in the glossary.Binary treesA worthwhile simplification is to consider only binary trees. A binary tree is one in which each node hasat most two descendants - a node can have just one but it can't have more than two.Clearly each node in a binary tree can have a left and/or a right descendant. The importance of a binarytree is that it can create a data structure that mimics a "yes/no" decision making process.For example, if you construct a binary tree to store numeric values such that each left sub-tree containslarger values and each right sub-tree contains smaller values then it is easy to search the tree for anyparticular value. The algorithm is simply a tree search equivalent of a binary search:start at the root
REPEAT until you reach a terminal nodeIF value at the node = search valueTHEN foundIF value at node < search valueTHEN move to left descendantELSE move to right descendantEND REPEATOf course if the loop terminates because it reaches a terminal node then the search value isn't in the tree,but the fine detail only obscures the basic principles.
Upload your study docs or become a
Course Hero member to access this document
Upload your study docs or become a
Course Hero member to access this document
End of preview. Want to read all 15 pages?
Upload your study docs or become a
Course Hero member to access this document