Copyright © Cengage Learning. All rights reserved.

Slides:



Advertisements
Similar presentations
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Advertisements

COUNTING AND PROBABILITY
COGN1001: Introduction to Cognitive Science Topics in Computer Science Formal Languages and Models of Computation Qiang HUO Department of Computer.
Chapter Chapter Summary Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output Language Recognition Turing.
Copyright © Cengage Learning. All rights reserved. CHAPTER 2 THE LOGIC OF COMPOUND STATEMENTS THE LOGIC OF COMPOUND STATEMENTS.
Copyright © Cengage Learning. All rights reserved. CHAPTER 1 SPEAKING MATHEMATICALLY SPEAKING MATHEMATICALLY.
ISBN Chapter 3 Describing Syntax and Semantics.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
PZ02A - Language translation
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Copyright © Cengage Learning. All rights reserved. CHAPTER 9 COUNTING AND PROBABILITY.
Copyright © Cengage Learning. All rights reserved.
ParsingParsing. 2 Front-End: Parser  Checks the stream of words and their parts of speech for grammatical correctness scannerparser source code tokens.
Copyright © Cengage Learning. All rights reserved. CHAPTER 2 THE LOGIC OF COMPOUND STATEMENTS THE LOGIC OF COMPOUND STATEMENTS.
The Mathematics of Networks Chapter 7. Trees A tree is a graph that –Is connected –Has no circuits Tree.
Languages and Grammars MSU CSE 260. Outline Introduction: E xample Phrase-Structure Grammars: Terminology, Definition, Derivation, Language of a Grammar,
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley.
Copyright © Cengage Learning. All rights reserved. CHAPTER 11 ANALYSIS OF ALGORITHM EFFICIENCY ANALYSIS OF ALGORITHM EFFICIENCY.
Copyright © Cengage Learning. All rights reserved.
Introduction Syntax: form of a sentence (is it valid) Semantics: meaning of a sentence Valid: the frog writes neatly Invalid: swims quickly mathematics.
Copyright © Cengage Learning. All rights reserved. 3 Applications of Differentiation.
Copyright © Cengage Learning. All rights reserved. CHAPTER 9 COUNTING AND PROBABILITY.
Copyright © Cengage Learning. All rights reserved. CHAPTER 10 GRAPHS AND TREES.
(CSC 102) Lecture 29 Discrete Structures. Graphs.
1 Chapter 3 Describing Syntax and Semantics. 3.1 Introduction Providing a concise yet understandable description of a programming language is difficult.
A sentence (S) is composed of a noun phrase (NP) and a verb phrase (VP). A noun phrase may be composed of a determiner (D/DET) and a noun (N). A noun phrase.
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
CS Describing Syntax CS 3360 Spring 2012 Sec Adapted from Addison Wesley’s lecture notes (Copyright © 2004 Pearson Addison Wesley)
Copyright © Cengage Learning. All rights reserved. CHAPTER 10 GRAPHS AND TREES.
ProgrammingLanguages Programming Languages Language Syntax This lecture introduces the the lexical structure of programming languages; the context-free.
ISBN Chapter 3 Describing Syntax and Semantics.
Copyright © Cengage Learning. All rights reserved. 2 Limits and Derivatives.
Copyright © Cengage Learning. All rights reserved. CHAPTER 7 FUNCTIONS.
1 Syntax In Text: Chapter 3. 2 Chapter 3: Syntax and Semantics Outline Syntax: Recognizer vs. generator BNF EBNF.
Copyright © Curt Hill Languages and Grammars This is not English Class. But there is a resemblance.
The College of Saint Rose CIS 433 – Programming Languages David Goldschmidt, Ph.D. from Concepts of Programming Languages, 9th edition by Robert W. Sebesta,
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Copyright © Cengage Learning. All rights reserved. 1 Whole Numbers.
Copyright © Cengage Learning. All rights reserved. 2 Limits and Derivatives.
Chapter 3 Describing Syntax and Semantics
COSC 2007 Data Structures II Chapter 14 Graphs I.
1 Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
ISBN Chapter 3 Describing Syntax and Semantics.
Aaron Tan 12. Graphs and Trees November 2015
Copyright © Cengage Learning. All rights reserved. CHAPTER 8 RELATIONS.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Syntax.
7.2 Programming Languages - An Introduction to Informatics WMN Lab. Hye-Jin Lee.
(CSC 102) Lecture 30 Discrete Structures. Graphs.
Organization of Programming Languages Meeting 3 January 15, 2016.
PROGRAMMING LANGUAGES
Graphs: Definitions and Basic Properties
Copyright © Cengage Learning. All rights reserved.
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved.
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley.
Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved.
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved.
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Presentation transcript:

Copyright © Cengage Learning. All rights reserved. CHAPTER 10 GRAPHS AND TREES Copyright © Cengage Learning. All rights reserved.

Copyright © Cengage Learning. All rights reserved. SECTION 10.5 Trees Copyright © Cengage Learning. All rights reserved.

Trees In mathematics, a tree is a connected graph that does not contain any circuits. Mathematical trees are similar in certain ways to their botanical namesakes.

Example of Trees

Example of Trees The next example illustrates a varied situation in which mathematical trees arise.

Example 3 – A Parse Tree In the last 30 years, Noam Chomsky and others have developed new ways to describe the syntax (or grammatical structure) of natural languages such as English. This work has proved useful in constructing compilers for high level computer languages. In the study of grammars, trees are often used to show the derivation of grammatically correct sentences from certain basic rules. Such trees are called syntactic derivation trees or parse trees.

Example 3 – A Parse Tree cont’d A very small subset of English grammar, for example, specifies that 1. a sentence can be produced by writing first a noun phrase and then a verb phrase; 2. a noun phrase can be produced by writing an article and then a noun; 3. a noun phrase can also be produced by writing an article, then an adjective, and then a noun; 4. a verb phrase can be produced by writing a verb and then a noun phrase;

Example 3 – A Parse Tree 5. one article is “the”; cont’d 5. one article is “the”; 6. one adjective is “young”; 7. one verb is “caught”; 8. one noun is “man”; 9. one (other) noun is “ball.”

Example 3 – A Parse Tree cont’d The rules of a grammar are called productions. It is customary to express them using the shorthand notation illustrated below. 1. 2., 3. 4. 5.

Example 3 – A Parse Tree cont’d 6. 7. 8. This notation, introduced by John Backus in 1959 and modified by Peter Naur in 1960, was used to describe the computer language Algol and is called the Backus-Naur notation.

Example 3 – A Parse Tree cont’d In the notation, the symbol | represents the word or, and angle brackets are used to enclose terms to be defined (such as a sentence or noun phrase). The derivation of the sentence “The young man caught the ball” from the mentioned rules is described by the tree shown below.

Example 3 – A Parse Tree cont’d In the study of linguistics, syntax refers to the grammatical structure of sentences, and semantics refers to the meanings of words and their interrelations. A sentence can be syntactically correct but semantically incorrect, as in the nonsensical sentence “The young ball caught the man,” which can be derived from the rules given before. Or a sentence can contain syntactic errors but not semantic ones, as, for instance, when a two-year-old child says, “Me hungry!”

Characterizing Trees

Characterizing Trees There is a somewhat surprising relation between the number of vertices and the number of edges of a tree. It turns out that if n is a positive integer, then any tree with n vertices (no matter what its shape) has n – 1 edges. Perhaps even more surprisingly, a partial converse to this fact is also true—namely, any connected graph with n vertices and n – 1 edges is a tree. It follows from these facts that if even one new edge (but no new vertex) is added to a tree, the resulting graph must contain a circuit.

Characterizing Trees Also, from the fact that removing an edge from a circuit does not disconnect a graph, it can be shown that every connected graph has a subgraph that is a tree. It follows that if n is a positive integer, any graph with n vertices and fewer than n – 1 edges is not connected. A small but very important fact necessary to derive the first main theorem about trees is that any nontrivial tree must have at least one vertex of degree 1.

Characterizing Trees A constructive way to understand this lemma is to imagine being given a tree T with more than one vertex. You pick a vertex v at random and then search outward along a path from v looking for a vertex of degree 1. As you reach each new vertex, you check whether it has degree 1. If it does, you are finished. If it does not, you exit from the vertex along a different edge from the one you entered on.

Characterizing Trees Because T is circuit-free, the vertices included in the path never repeat. And since the number of vertices of T is finite, the process of building a path must eventually terminate. When that happens, the final vertex v  of the path must have degree 1. This process is illustrated below.

Characterizing Trees Using Lemma 10.5.1 it is not difficult to show that, in fact, any tree that has more than one vertex has at least two vertices of degree 1.

Example 5 – Terminal and Internal Vertices Find all terminal vertices and all internal vertices in the following tree: Solution: The terminal vertices are v0, v2, v4, v5, v7, and v8. The internal vertices are v6, v1, and v3.

Characterizing Trees The following is the first of the two main theorems about trees:

Example 7 – Finding Trees Satisfying Given Conditions Find all nonisomorphic trees with four vertices. Solution: By Theorem 10.5.2, any tree with four vertices has three edges. Thus the total degree of a tree with four vertices must be 6. Also, every tree with more than one vertex has at least two vertices of degree 1.

Example 7 – Solution cont’d Thus the following combinations of degrees for the vertices are the only ones possible: 1, 1, 1, 3 and 1, 1, 2, 2. There are two nonisomorphic trees corresponding to both of these possibilities, as shown below.

Characterizing Trees Essentially, the reason why Lemma 10.5.3 is true is that any two vertices in a circuit are connected by two distinct paths. It is possible to draw the graph so that one of these goes “clockwise” and the other goes “counterclockwise” around the circuit.

Characterizing Trees For example, in the circuit shown below, the clockwise path from v2 to v3 is and the counterclockwise path from v2 to v3 is

Characterizing Trees The second major theorem about trees is a modified converse to Theorem 10.5.2. Theorem 10.5.4 is not a full converse of Theorem 10.5.2. Although it is true that every connected graph with n vertices and n – 1 edges (where n is a positive integer) is a tree, it is not true that every graph with n vertices and n – 1 edges is a tree.

Example 8 – A Graph with n Vertices and n – 1 Edges That Is Not a Tree Give an example of a graph with five vertices and four edges that is not a tree. Solution: By Theorem 10.5.4, such a graph cannot be connected. One example of such an unconnected graph is shown below.