Presentation is loading. Please wait.

Presentation is loading. Please wait.

Representing Structure and Behavior with Trees

Similar presentations


Presentation on theme: "Representing Structure and Behavior with Trees"— Presentation transcript:

1 Representing Structure and Behavior with Trees
CS1316: Representing Structure and Behavior

2 Story What trees are good for. What we were just doing with LLNode
What linked lists are good for. Using linked lists to represent structure and behavior What trees are good for. Using trees to represent structure and behavior Examples Equations Matching Unification

3 Abstracting LLNode abstract LLNode Knows next
Knows how to do all basic list operations

4 CollectableNode Knows just knows the part that specializes LLNode for collectable (sound-returning) nodes.

5 DrawableNode Just specializes LLNode to represent things that can draw with a turtle and draw down their linked list with a turtle (drawOn).

6 LLNode: The abstract definition of what a linked list node is
Given LLNode, we can make anything we want into a linked list. Want a linked list of students? Subclass LLNode into StudentNode StudentNodes know names and ID numbers, and know how to access and return these. The linked list part is inherited from LLNode. Every StudentNode knows next and knows how to getNext, add, etc.

7 Why do people use linked lists?
Whenever you want dynamic size to the list, You may want the ordering to represent something, You want insertion and deletion to be cheap and easy, You are willing to make finding a particular item slower.

8 Examples of Linked Lists
Order of layers in Visio or PowerPoint Notes in a Phrase in JMusic Video segments in non-linear video editing. Items in a toolbar. Slides in a PowerPoint presentation.

9 But what are trees good for?
Trees represent hierarchical structure. When just representing ordering (linearity) isn’t enough. Trees can store operations (behavior), as well as data. Linked lists can, too, but not as useful.

10 Examples of Trees Representing how parts of music assemble to form a whole. Representing the elements of a scene. Scene graph Representing the inheritance relationships among classes. Class hierarchy Files and directories on your hard disk. Elements in an HTML page. Organization chart Political affiliations

11 Example Tree: Equation
It’s fairly easy to turn an equation into a tree. If you see an operation, make a branch. Otherwise, make a node. The structure here represents order of operation. Evaluating this tree is like collecting() the sounds, but collection involves computation (behavior) at the branches. 3 + 4 * 5 + 3 * 4 5

12 Example Tree: Taxonomies (Keeping track of meaning)
Let’s say that you want to compare prices at various websites for the same item. At one site, they call it the “retail price” At another, they call it the “customer’s cost” How do you track that these are similar meanings? It’s the same as knowing that a MoveBranch is a kind of Branch is a kind of DrawableNode!

13 Tree of Meanings Here, the arrows mean the same thing as in a class hierarchy. The thing below is a specialization of the thing above. Artificial Intelligence (AI) and Semantic Web researchers really do represent taxonomies in just this way. Price Retail price Wholesale price Customer cost Business-to-business price Customer price

14 Algorithm for matching
Traverse the tree to find phrase1. Traverse the tree to find phrase2. Do both have a common ancestor (parent)? That’s the meaning in common! If not, need to extend the taxonomy.

15 Example tree: Unification
My cat ate a fat worm. Sentence Diagrams are trees. Arrows don’t mean the same things here. Some arrows are saying instance-of a category (like “noun”) Other arrows are saying has-pieces-within (like links from “subject” and “object”) ate verb subject object noun article noun cat adjective adjective a worm My fat

16 How do we search a collection of sentence diagrams?
Imagine: You’re an expert with the National Security Agency. You have megabytes of captured terrorist messages. Using specialized Natural Language Understanding (NLU) technology, you have trees of all this text. Now what do you do with it?

17 Compare trees attack We can create a tree describing the kind of sentence that we want to find. We leave variables that can be bound in the process of the query. Matching complex trees like this is sometimes called unification. Not exactly the same word? How do we determine if it’s close enough? See previous slides… verb subject object noun noun <suspect> <location in United States>

18 Trees in User Interfaces
Any user interface is actually composed of a tree! Windows hold panes hold buttons and text areas. Next lecture… window pane pane button text area button button


Download ppt "Representing Structure and Behavior with Trees"

Similar presentations


Ads by Google