Set Theory
Set Theory
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, AB
if for all xA, xB.
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 AB.
We still have to define what { 2x | xN } 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
2|Page
Formal Language and automata Assignment
3|Page
Formal Language and automata Assignment
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.
4|Page
Formal Language and automata Assignment
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
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 (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.
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
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.
10 | P a g e
Formal Language and automata Assignment
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
Descriptive: attempts to describe actual usage rather than enforce arbitrary rules
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