ArticleslgStudy

computer science

Parse tree

Parse tree is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Parse tree rather than just read about it. In short: A parse tree or parsing tree (also known as a derivation tree or concrete syntax tree) is an ordered, rooted tree that represents the syntactic structure of a string according to some context-free grammar. The term parse tree itself is used primarily in computational linguistics; in theoretical syntax, the term syntax tree is more common.

Parse tree — main illustration
Parse tree — illustration

Key takeaways

  • Parse tree belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Parse tree to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Parse tree from memory before moving on to harder problems.

Reference excerpt

A parse tree or parsing tree (also known as a derivation tree or concrete syntax tree) is an ordered, rooted tree that represents the syntactic structure of a string according to some context-free grammar. The term parse tree itself is used primarily in computational linguistics; in theoretical syntax, the term syntax tree is more common. Concrete syntax trees reflect the syntax of the input language, making them distinct from the abstract syntax trees used in computer programming. Unlike Reed-Kellogg sentence diagrams used for teaching grammar, parse trees do not use distinct symbol shapes for different types of constituents. Parse trees are usually constructed based on either the constituency relation of constituency grammars (phrase structure grammars) or the dependency relation of dependency grammars. Parse trees may be generated for sentences in natural languages (see natural language processing), as well as during processing of computer languages, such as programming languages. A related concept is that of phrase marker or P-marker, as used in transformational generative grammar. A phrase marker is a linguistic expression marked as to its phrase structure. This may be presented in the form of a tree, or as a bracketed expression. Phrase markers are generated by applying phrase structure rules, and themselves are subject to further transformational rules. A set of possible parse trees for a syntactically ambiguous sentence is called a "parse forest".

History A form of parse tree was in use as early as 1879 in Gottlob Frege's Begriffsschrift book.

Nomenclature

A parse tree is made up of nodes and branches. In the picture the parse tree is the entire structure, starting from S and ending in each of the leaf nodes (John, ball, the, hit). In a parse tree, each node is either a root node, a branch node, or a leaf node. In the above example, S is a root node, NP and VP are branch nodes, while John, ball, the, and hit are all leaf nodes. Nodes can also be referred to as parent nodes and child nodes. A parent node is one which has at least one other node linked by a branch under it. In the example, S is a parent of both NP and VP. A child node is one which has at least one node directly above it to which it is linked by a branch of the tree. Again from our example, hit is a child node of V. A nonterminal function is a function (node) which is either a root or a branch in that tree whereas a terminal function is a function (node) in a parse tree which is a leaf. For binary trees (where each parent node has two immediate child nodes), the number of possible parse trees for a sentence with n words is given by the Catalan number C n {\displaystyle C_{n}} .

Constituency-based parse trees The constituency-based parse trees of constituency grammars (phrase structure grammars) distinguish between terminal and non-terminal nodes. The interior nodes are labeled by non-terminal categories of the grammar, while the leaf nodes are labeled by terminal categories. The image below represents a constituency-based parse tree; it shows the syntactic structure of the English sentence John hit the ball:

The parse tree is the entire structure, starting from S and ending in each of the leaf nodes (John, hit, the, ball). The following abbreviations are used in the tree:

S for sentence, the top-level structure in this example. NP for noun phrase. The first (leftmost) NP, a single noun John, serves as the subject of the sentence. The second one is the object of the sentence. VP for verb phrase, which serves as the predicate. V for verb; in this case, it's the transitive verb hit. D for determiner; in this instance the definite article the. N for noun; in this case ball. Each node in the tree is either a root node, a branch node, or a leaf node. A root node is a node that does not have any branches on top of it. Within a sentence, there is only ever one root node. A branch node is a parent node that connects to two or more child nodes. A leaf node, however, is a terminal node that does not dominate other nodes in the tree. S is the root node, NP and VP are branch nodes, and John (N), hit (V), the (D), and ball (N) are all leaf nodes. The leaves are the lexical tokens of the sentence. A parent node is one that has at least one other node linked by a branch under it. In the example, S is a parent of both N and VP. A child node is one that has at least one node directly above it to which it is linked by a branch of a tree. From the example, hit is a child node of V. The terms mother and daughter are also sometimes used for this relationship.

Dependency-based parse trees The dependency-based parse trees of dependency grammars see all nodes as terminal, which means they do not acknowledge the distinction between terminal and non-terminal categories. They are simpler on average than constituency-based parse trees because they contain fewer nodes. The dependency-based parse tree for the example sentence above is as follows:

This parse tree lacks the phrasal categories (S, VP, and NP) seen in the constituency-based counterpart above. Like the constituency-based tree, constituent structure is acknowledged. Any complete sub-tree of the tree is a constituent. Thus this dependency-based parse tree acknowledges the subject noun John and the object noun phrase the ball as constituents just like the constituency-based parse tree does. The constituency vs. dependency distinction is far-reaching. Whether the additional syntactic structure associated with constituency-based parse trees is necessary or beneficial is a matter of debate.

Phrase markers Phrase markers, or P-markers, were introduced in early transformational generative grammar, as developed by Noam Chomsky and others. A phrase marker representing the deep structure of a sentence is generated by applying phrase structure rules. Then, this application may undergo further transformations. Phrase markers may be presented in the form of trees (as in the above section on constituency-based parse trees), but are often given instead in the form of "bracketed expressions", which occupy less space in the memory. For example, a bracketed expression corresponding to the constituency-based tree given above may be something like:

… excerpt ends here. Continue reading the full article.

Illustrations

Parse tree: Parse tree of the string "aab" with respect to the production rules 
  
    
      
        
          
            
              
                
                  S
                
              
              
                →
              
              
                
                  AB
                
              
            
            
              
                
                  A
                
              
              
                →
              
              
                
                  aA
                
              
            
            
              
                
                  A
                
              
              
                →
              
              
                ε
              
            
            
              
                
                  B
                
              
              
                →
              
              
                
                  b
                
              
            
          
        
      
    
    {\displaystyle {\begin{matrix}{\text{S}}&\to &{\text{AB}}\\{\text{A}}&\to &{\text{aA}}\\{\text{A}}&\to &\varepsilon \\{\text{B}}&\to &{\text{b}}\end{matrix}}}
Parse tree of the string "aab" with respect to the production rules S → AB A → aA A → ε B → b {\displaystyle {\begin{matrix}{\text{S}}&\to &{\text{AB}}\\{\text{A}}&\to &{\text{aA}}\\{\text{A}}&\to &\varepsilon \\{\text{B}}&\to &{\text{b}}\end{matrix}}}
Parse tree: A simple parse tree
A simple parse tree
Parse tree illustration
Parse tree illustration

Worked examples

Example 1 — a first encounter with Parse tree

Start with the simplest possible case. Write down what Parse tree claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Parse tree before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Parse tree ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Parse tree

In research
Parse tree appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Parse tree in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Parse tree is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computational linguistics, Generative syntax, Mathematical linguistics, so understanding it makes those chapters shorter.
In everyday life
Look for Parse tree outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Parse tree” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Parse tree in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Parse tree means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Parse tree out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Parse tree in simple terms?

A parse tree or parsing tree (also known as a derivation tree or concrete syntax tree) is an ordered, rooted tree that represents the syntactic structure of a string according to some context-free grammar. The term parse tree itself is used primarily in computational linguistics; in theoretical syn…

Why does Parse tree matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Parse tree?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Parse tree.

Tags

  • Computational linguistics
  • Generative syntax
  • Mathematical linguistics
  • Syntax
  • Trees (data structures)

Keep exploring