You are on page 1of 12

Formal Language and automata Assignment

1. Set Theory
A set is a collection of objects, or elements. Typically, the type of all the elements in a set is the
same. (For example, all the elements in a set could be integers.) However, it is possible to have
different types of elements in a set. (An analogy for this is that usually a book bag contains just
books. But sometimes it may contain other elements such as pencils and folders as well.)
A set is a well-defined collection of objects. The objects are called the elements and are usually
denoted by lowercase letters a, b, c, …; the sets themselves are usually denoted by uppercase
letters A, B, C, ….
The elements of a set may be displayed using roster notation by listing each element between
braces (ex. B = { a, b, c, . . . , z }) or by roster notation by giving a rule that describes the
definite property or properties an object x must satisfy to qualify for membership in the set (ex. B
= {x | x is a letter of the English alphabet}.
We have two usual methods of denoting the elements in a set:
1. Explicitly list the elements inside of a set of curly braces ({}), as follows: {1, 2, 3, 4}
2) Give a description of the elements in a set inside of a set of curly braces as follows: { 2x |
x}.
In order to understand the second method, we must define the various symbols that are used in
this notation. Here is a list of the symbols we will be using:
| - translates to “such that”
- “is an element of”
- “is a proper subset of”
- “is a subset of”
Now we have to define what a subset is. A subset is also a set. So, if we have sets A and B, AB
if for all xA, xB.
In layman’s terms, a set A is a subset of a set B, if all the elements in the set A also lie in the set
B.
Note: A  B iff A  B  AB.
We still have to define what { 2x | xN } really means. Here it is in English:
“The set of all numbers of the form 2x such that x is an element of the natural numbers.” (Note:
The set N denotes the natural numbers, or the non-negative integers, according to the book.)

1|Page
Formal Language and automata Assignment

So, the set above could also be listed as {0, 2, 4, 6, ...}


Now that we have gotten that out of the way, let’s talk about the empty set(). The empty set is
a set with no elements in it. In our standard notation, we could denote it as {}. It is also very
common to use , to denote the empty set.
It’s important to denote that the following are not equal:
 , {0}, and 0.
The first two are sets, while the third is an element. However, the empty set has no elements
while {0} contains one element, zero.
Typically, sets will be denoted by uppercase letters. There are some other sets we should be
familiar with since they come up so often. Here they are:
Z = {0, 1, -1, 2, -2, ...} (the set of integers)
N = {0, 1, 2, 3, ...} (the set of non-negative integers)
Z+ = {1, 2, 3, ...} (the set of positive integers)
Q = {a/b | a, bZ  b0}
R = the set of real numbers...
Also, one last definition... |A| for a set a is known as the “cardinality” of A, which equals the
number of elements in A.
 Two sets A and B are equal iff they have exactly the same elements.
Example 1: Let A, B, and C be the sets
A = {a, e, i, o, u}
B = {a, i, o, e, u}
C = {a, e, i, o}
A = B since they both contain exactly the same elements. A  C since u  A but u  C. Also, B
 C.
If every element of a set A is also an element of a set B, then we say that A is a subset of B (A 
B).
Example 2: Let A, B, C, and C be the sets
A = {a, e, i, o, u}
B = {a, i, o, e, u}
C = {a, e, i, o}
D = {a, e, i, o, x}

2|Page
Formal Language and automata Assignment

C  since every element of C is also an element of B. D  A since x  D but x  D.


If A and B are sets such that A  B but A  B, then A is a proper subset of B (A  B).
Example 3: Let A = {1, 2, 3, 4, 5, 6} and B = {2, 3, 6}.
B is a proper subset of A since (1) B  A, and (2) there exists at least one element in A that is not
in B.
The set that contains no elements is called the empty set and is denoted by .
Example 4: List all subsets of the set A = {a, b, c}.
The universal set is the set of all elements of interest in a particular discussion. It is the largest
in the sense that all sets considered in the discussion of the problem are subsets of the universal
set.
Example 5: Give the universal set for each situation:
a) Determine the ratio of female to male students in a college.
b) Determine the ratio of female to male students in the business department of the
college.
Venn diagrams are used as a visual representation of sets. The universal set U is
represented b

2. Relation and function


Relations
A relation is a set of inputs and outputs, often written as ordered pairs (input, output). We can
also represent a relation as a mapping diagram or a graph. A relation is a way of expressing a
connection or relationship between any two pieces of information for example, the relation can
be represented as:

3|Page
Formal Language and automata Assignment

If A and B are two non-empty sets, then a relation R from A to B is a subset of A x B. If R ⊆ A x


B and (a, b) ∈ R, then we say that a is related to b by the relation R, written as aRb. Domain and
Range of a Relation Let R be a relation from a set A to set B. Then, set of all first components or
coordinates of the ordered pairs belonging to R is called : the domain of R, while the set of all
second components or coordinates = of the ordered pairs belonging to R is called the range of R.
Thus, domain of R = {a : (a , b) ∈ R} and range of R = {b : (a, b) ∈ R} Types of Relations (i)
Void Relation As Φ ⊂ A x A, for any set A, so Φ is a relation on A, called the empty or void
relation. (ii) Universal Relation Since, A x A ⊆ A x A, so A x A is a relation on A, called the
universal relation. (iii) Identity Relation The relation IA = {(a, a) : a ∈ A} is called the identity
relation on A. (iv) Reflexive Relation A relation R is said to be reflexive relation, if every
element of A is related to itself. Thus, (a, a) ∈ R, ∀ a ∈ A = R is reflexive. (v) Symmetric
Relation A relation R is said to be symmetric relation, iff (a, b) ∈ R (b, a) ∈ R,∀ a, b ∈ A i.e., a R
b ⇒ b R a,∀ a, b ∈ A ⇒ R is symmetric. (vi) Anti-Symmetric Relation A relation R is said to be
anti-symmetric relation, iff (a, b) ∈ R and (b, a) ∈ R ⇒ a = b,∀ a, b ∈ A

function
A function is a particular kind of relation between sets. A function takes every element x in a
starting set, called the domain, and tells us how to assign it to exactly one element y in an ending
set, called the range.
A function is a "well-behaved" relation. Just as with members of your own family, some
members of the family of pairing relationships are better behaved than other. (Warning: This
means that, while all functions are relations, since they pair information, not all relations are
functions. Functions are a sub-classification of relations.) When we say that a function is "a well-
behaved relation", we mean that, given a starting point, we know exactly where to go; given an x,
we get only and exactly one y.

From the figure below example we can able to find the difference between relation and function.

Every function is a relation, but every relation doesn't represent a function

4|Page
Formal Language and automata Assignment

3.Graph and tree


Graph is an abstract data type
It is a pictorial representation of a set of objects where some pairs of objects are
connected by links.
Graph is used to implement the undirected graph and directed graph concepts from
mathematics
It represents many real life applications. Graphs are used to represent the networks.
Network includes path in a city, telephone network etc.
It is used in social networks like Facebook, LinkedIn etc.
Graph consists of two following components:
1. Vertices
2. Edges
 Graph is a set of vertices (V) and set of edges (E).
 V is a finite number of vertices also called as nodes.
 E is a set of ordered pair of vertices representing edges.

5|Page
Formal Language and automata Assignment

 For example, in Facebook, each person is represented with a vertex or a node. Each node is a
structure and contains the information like user id, user name, gender etc.

 The above figures represent the graphs. The set representation for each
of these graphs are as follows:
Graph 1:

V = {A, B, C, D, E, F}
E = {(A, B), (A, C), (B, C), (B, D), (D, E), (D, F), (E, F)}

Graph 2:

V = {A, B, C, D, E, F}
E = {(A, B), (A, C), (B, D), (C, E), (C, F)}

Graph 3:

V = {A, B, C}
E = {(A, B), (A, C), (C, B)}
Types of graph
 Directed graph
 Undirected graph
 Cyclic graph
 Unicycle graph
 Complete graph
 Uncompleted graph
 Weighted graph
 Unweighted graph
 Etc.

6|Page
Formal Language and automata Assignment

TREE
Tree in computer science is like a tree in the real world, the only difference is that in computer
science it is visualized as upside-down with root on the top and branches originating from the
root to the leaves of the tree. Tree Data Structure is used for various real-world applications as it
can show relation among various nodes using the parent-child hierarchy. Due to this it is also
known as hierarchical data structure. It is widely used to simplify and fasten searching and
sorting operations. It is considered to be one of the most powerful and advanced data structures.
 Tree is a hierarchical data structure which stores the information naturally in the form of
hierarchy style.
 Tree is one of the most powerful and advanced data structures.
 It is a non-linear data structure compared to arrays, linked lists, stack and queue.
 It represents the nodes connected by edges.

Properties of Tree:
 Every tree has a special node called the root node. The root node can be used to traverse
every node of the tree. It is called root because the tree originated from root only.
 If a tree has N vertices(nodes) than the number of edges is always one less than the number
of nodes(vertices) i. e N-1. If it has more than N-1 edges it is called a graph not a tree.
 Every child has only a single Parent but Parent can have multiple child

Types of Trees in Data Structure


7|Page
Formal Language and automata Assignment

General Tree

A tree is called a general tree when there is no constraint imposed on the hierarchy of the tree. In
General Tree, each node can have infinite number of children. This tree is the super-set of all
other types of trees.

Binary Tree

Binary tree is the type of tree in which each parent can have at most two children. The children
are referred to as left child or right child. This is one of the most commonly used trees. When
certain constraints and properties are imposed on Binary tree it results in a number of other
widely used trees like BST (Binary Search Tree), AVL tree, RBT tree etc.

Binary Search Tree

Binary Search Tree (BST) is an extension of Binary tree with some added constraints. In BST,
the value of the left child of a node must be smaller than or equal to the value of its parent and
the value of the right child is always larger than or equal to the value of its parent. This property
of Binary Search Tree makes it suitable for searching operations as at each node we can decide
accurately whether the value will be in left subtree or right subtree. Therefore, it is called a
Search Tree.

Fig 3: Binary Search Tree (Source)

AVL Tree

8|Page
Formal Language and automata Assignment

AVL tree is a self-balancing binary search tree. The name AVL is given on the name of its
inventors Adelson-Velshi and Landis. This was the first dynamically balancing tree. In AVL
tree, each node is assigned a balancing factor based on which it is calculated whether the tree is
balanced or not. In AVL tree, the heights of children of a node differ by at most 1. The valid
balancing factor in AVL tree are 1, 0 and -1. When a new node is added to the AVL tree and
tree becomes unbalanced then rotation is done to make sure that the tree remains balanced. The
common operations like lookup, insertion and deletion takes O(log n) time in AVL tree. It is
widely used for Lookup operations.

Fig 4: Source

Red-Black Tree

Red-Black is another type of self-balancing tree. The name Red-Black is given to it because each
node in a Red-Black tree is either painted Red or Black according to the properties of the Red-
Black Tree. This make sure that the tree remains balanced. Although the Red-Black tree is not a
perfectly balanced tree but its properties ensure that the searching operation takes only O(log n)
time. Whenever a new node is added to the Red-Black Tree, the nodes are rotated and painted
again if needed to maintain the properties of the Red-Black Tree .

9|Page
Formal Language and automata Assignment

Fig 5: Red-Black Tree (Source)

N-ary Tree

In an N-ary tree, the maximum number of children that a node can have is limited to N. A binary
tree is 2-ary tree as each node in binary tree has at most 2 children. Trie data structure is one of
the most commonly used implementation of N-ary tree. A full N-ary tree is a tree in which
children of a node is either 0 or N. A complete N-ary tree is the tree in which all the leaf nodes
are at the same level.

Fig 6: N-ary tree (5-ary)

10 | P a g e
Formal Language and automata Assignment

4.Language and Grammar

Grammar
It is often convenient to specify languages in terms of grammars. The advantage in doing so
arises mainly from the usage of a small number of rules for describing a language with a large
number of sentences. For instance, the possibility that an English sentence consists of a subject
phrase followed by a predicate phrase can be expressed by a grammatical rule of the form . (The
names in angular brackets are assumed to belong to the grammar metalanguage.) Similarly, the
possibility that the subject phrase consists of a noun phrase can be expressed by a grammatical
rule of the form . G is defined as a mathematical system consisting of a quadruple , where N : is
an alphabet, whose elements are called non terminal symbols. : is an alphabet disjoint from N,
whose elements are called terminal symbols. P :is a relation of finite cardinality on (N )*, whose
elements are called production rules. Moreover, each production rule ( , ) in P, denoted , must
have at least one nonterminal

Types of grammars

Prescriptive: prescribes authoritative norms for a language

Descriptive: attempts to describe actual usage rather than enforce arbitrary rules

Formal: a precisely defined grammar, such as context

Generative: a formal grammar that can generate natural language expressions

A grammar is a set of production rules which are used to generate strings of a language. In this
article, we have discussed how to find the language generated by a grammar and vice versa as
well.
language
The alphabet of a formal language is the set of symbols, letters, or tokens from which the strings
of the language may be formed; frequently it is required to be finite. The strings formed from this
alphabet are called words, and the words that belong to a particular formal language are
sometimes called well-formed words or well-formed formulas. A formal language is often
defined by means of a formal grammar such as a regular grammar or context-free grammar, also
called its formation rule. The field of formal language theory studies the purely syntactical

11 | P a g e
Formal Language and automata Assignment

aspects of such languages— that is, their internal structural patterns. Formal language theory
sprang out of linguistics, as a way of understanding the syntactic regularities of natural
languages. In computer science, formal languages are often used as the basis for defining
programming languages and other systems in which the words of the language are associated
with particular meanings or semantics. A formal language L over an alphabet Σ is a subset of Σ*,
that is, a set of words over that alphabet. In computer science and mathematics, which do not
usually deal with natural languages, the adjective "formal" is often omitted as redundant. While
formal language theory usually concerns itself with formal languages that are described by some
syntactical rules, the actual definition of the concept "formal language" is only as above: a
(possibly infinite) set of finite-length strings, no more nor less. In practice, there are many
languages that can be described by rules, such as regular languages or context-free languages.
The notion of a formal grammar may be closer to the intuitive concept of a "language," one
described by syntactic rules.

12 | P a g e

You might also like