180 likes | 448 Views
Trees. Example Tree. Formal Definition (from Google’s define:tree ). In graph theory, a directed acyclic graph (DAG) in which the root node has no parent and every other node has exactly one parent. www.mindspring.com/~scarlson/tc/glossary.htm
E N D
Formal Definition (from Google’s define:tree) • In graph theory, a directed acyclic graph (DAG) in which the root node has no parent and every other node has exactly one parent.www.mindspring.com/~scarlson/tc/glossary.htm • In computer science, a tree is a widely-used computer data structure that emulates a tree structure with a set of linked nodes. Each node has zero or more child nodes, which are below it in the tree (in computer science, unlike in nature, trees grow down, not up). A node that has a child is called the child's parent node. A child has at most one parent; a node without a parent is called the root node (or root). Nodes with no children are called leaf nodes. en.wikipedia.org/wiki/Tree_(computing)
Uses of Trees • Paragraph Numbering in a Document • Family (aSexual reproduction!) • File system e.g. Unix, Dos • Classification e.g. Linaus, Dewey • Hierarchical Database e.g. IBMs MIS, LDAP • Web site structure • Hierarchical Menu • Organisational Hierarchy • Class Hierarchy in Java • Assembly / Part hierarchy • Document Object Model • XML • B-tree for efficient indexing
File system • File system in Unix or Windows • C:\Program Files\eXist\webapp\admin\admin.xql • Actually this is a ‘Forest’ of trees, each drive a separate Tree
Taxonomy • Animal Kingdom • Home Kingdom Animalia Phylum Arthropoda Class Insecta Order Lepidoptera Suborder Macrolepidoptera Family Nymphalidae Species Vanessa atalanta • Knowledge • Dewey Decimal Classification • Finding Butterflies
Type (A Kind of) Hierarchyrelative to F G and H would inherit all the attributes and methods of F and define additional attributes and methods of their own. A type hierarchy allows sharing of definitions. [see ‘Normalisation’ Easily confused with an Object Hierarchy or Whole/Part hierarchy.
Object Hierarchy • An object hierarchy supports one or more of a number of kinds of relationship. • Containment: • One object is ‘contained’ within, is a part of, a parent object. A containment relationship is used to move, copy or delete a whole sub-tree. • Scoping: • Names of objects must be unique within some scope. Often these scopes are hierarchical. The name of a child is unique within the scope of the parent. • Delegation: (cascading, value inheritance • A child object delegates responsibility for a property to its parent, and so on up the hierarchy until an object defines the property. • Aggregation: • A parent object has properties determined by the properties of its children. For example, the value of the ‘cost’ in a non-leaf would be defined as the sum of cost values over all children, with actual cost values defined at the leaves. Min, max, average are other aggregate relationships. • Distribution: • A parent property is distributed over the children – for example a budget value defined in the parent is distributed over the children.
HTML Document (Object Tree) <html> <head> <title>Sample Document</title> </head> <body> <h1>An HTML Document</h1> <p>This is a <i>simple</i> document. </p> </body> </html> From Flanagan,D. (2002) JavaScript The Definitive Guide , O’Reilly [on-line]
DOM Class Tree From Flanagan,D. (2002) JavaScript The Definitive Guide , O’Reilly [on-line]
Exercise • file:///C:/Inetpub/wwwroot/a-xslt/xpathviz/XPathMainNS.htm
Exercises(based on hoax.xml) • Write XPath expressions to locate the following: • The recipe title • All recipe ingredients • The amount of brown sugar • The last instruction • Write DOM code to access the same data