Fafl Assignment Name: Prabhakar Gouda Assignment No: 01,02,03 Roll No: 35 Week No: 01 SEM: V Cs&E Section: B
Fafl Assignment Name: Prabhakar Gouda Assignment No: 01,02,03 Roll No: 35 Week No: 01 SEM: V Cs&E Section: B
1
Contents
2
0.1 Graphical representation of Daily
Routine.
Consider the set NODES
W:wokeup
B:breakfast
C:college
Li:library
L:launch
D:dinner
S:sleeping
Q={W,B,C,Li,L,D,S}
P
={t1,t2,t3,t4 .. . . tn} Different input times.
q0=W The initial state.
F={S}
We can represent the graph as:
Figure 1: graph
3
0.2 SET THEORY
0.2.1 Introduction
Sets are collections. The objects in the collection are its members.
E.g., we are all members of the set of all humans.
Anything can be in a set. There are sets of numbers, people, other sets.
{Ted, {New York City}, 57} The set containing me, the
set containing just NYC, and the
number 57
Its often intuitive to speak of collecting things together and putting them
into a set, but the idea is that the sets exist whether or not anyone has ever
done any collection. Moreover, notice that a sets members dont need to be
similar, or thought of by people, or anything like that. Except for certain
limitations well discuss later, any objects form a set.
Intersection
Let A and B be sets.
T
The intersection of A and B is the set, denoted by A B, whose elements
4
are exactly those sets belonging to both A and B.
For example,{0, 1, 2} ∩ {1, 2, 3, 4, 5, 6, 7, 8} = {1, 2}
Difference
Let A and B be sets.
The (relative) difference of A with B is the set, denoted by A - B, whose
elements are exactly those elements of A which do not belong to B.
For example, {0, 1, 2} - {1, 2, 3} = {0}.
Complement
Complement of set A relative to set U,denoted by Ac , is the set of all
members of U that are not members of A. This terminology is most commonly
employed when U is a universal set. This operation is also called the set
difference of U and A, denoted U - A.
The complement of {1,2,3} relative to {2,3,4} is {4},
while, conversely, the complement of {2,3,4} relative to {1,2,3} is {1}.
Catesian Product
Let A and B are sets, Cartesian product of A and B, denoted A X B, is the
set whose members are all possible ordered pairs (a,b) where a is a member
of A and b is a member of B.
For example,The Cartesian product of {0, 1, 2} and {3, 4} is
{{0, {0, 3}}, {0, {0, 4}}, {1, {1, 3}}, {1, {1, 4}}, {2, {2, 3}}, {2, {2, 4}}}.
The product of {3, 4} and {0, 1, 2} is
{{3, {0, 3}}, {3, {1, 3}}, {3, {2, 3}}, {4, {0, 4}}, {4, {1, 4}}, {4, {2, 4}}}.
Thus the Car- tesian product is not commutative.
Power set
The power set of a set A is the set whose members are all possible subsets of
A.
For example, the powerset of {1, 2} is { {}, {1}, {2}, {1,2} }.
Empty set
A set which has no elements is called an empty set or null set and is denoted
by { } or φ.For example the set S that does not contain any element can be
represented as,
S ={ } or S = φ
5
Subset
A set A is a subset of B if every element of A is in B and is denoted by A⊆B
If A ⊆ B and B contain an element which is not in A,th A is a proper subset
of B and is denoted by A ⊂ B.
Equal set
The two sets A and B are same iff A ⊆ B and B ⊆ A i.e.,every element of
set A is in B and every element is in B are the elements of A.
6
Sadly, this definition is not precise enough for mathematical discussion.
0.3.2 Definitions
A nuisance in first learning graph theory is that there are so many definitions.
They all correspond to intuitive ideas, but can take a while to absorb. Some
ideas have multi ple names. For example, graphs are sometimes called net-
works, vertices are sometimes called nodes, and edges are sometimes called
arcs. Even worse, no one can agree on the exact meanings of terms.
For example, in our definition, every graph must have at least one vertex.
However, other authors permit graphs with no vertices. (The graph with
no vertices is the single, stupid counterexample to many wouldbe theorems
so were banning it!) This is typical; everyone agrees moreorless what each
term means, but dis agrees about weird special cases. So do not be alarmed
if definitions here differ subtly from definitions you see elsewhere. Usually,
these differences do not matter.
7
Two vertices in a graph are said to be adjacent if they are joined by an
edge, and an edge is said to be incident to the vertices it joins. The number
of edges incident to a vertex is called the degree of the vertex. For example,
in the graph above, A is adjacent to B and B is adjacent to D, and the edge
AC is incident to vertices A and C. Vertex H has degree 1, D has degree 2,
and E has degree 3.
Figure 3: multigraph
The edges in a directed graph are arrows pointing to one endpoint or the
other.
Directed graphs are often called digraphs. We denote an edge from vertex
A to vertex B in a digraph by A B. Formally, the edges in a directed graph
are ordered pairs of vertices rather than sets of two vertices. The number
of edges directed into a vertex is called the indegree of the vertex, and the
number of edged directed out is called the outdegree.
8
One can also allow selfloops, edges with both endpoints at one vertex.
Combinations of these variations are also possible; for example, one could
work with directed multigraphs with selfloops.
Except where stated otherwise, the word graph in this course refers to a
graph without mul tiple edges, directed edges, or selfloops.
The Web Each vertex represents a web page. Directed edges between
vertices represent hyperlinks.
People often put numbers on the edges of a graph, put colors on the ver-
tices, or add other ornaments that capture additional aspects of the phe-
nomenon being modeled. For example, a graph of airline connections might
have numbers on the edges to indicate the duration of the corresponding
flight. The vertices in the attraction graph might be colored to indicate the
persons gender.
9
Some Common Graphs
Some graphs come up so frequently that they have names. The complete graph
on n vertices, also called Kn , has an edge between every pair of vertices.
Here is K5 :
0.3.5 Isomorphism
Two graphs that look the same might actually be different in a formal
sense. For example, the two graphs below are both cycles with 4 vertices:
Figure 5: Isomorphism
10
But one graph has vertex set {A, B, C, D} while the other has vertex set
{1, 2, 3, 4}. If so, then the graphs are different mathematical objects, strictly
speaking. But this is a frustrating distinction; the graphs look the same!
0.3.6 Connectivity
In the diagram below, the graph on the left has two pieces, while the graph
on the right has just one.
11
PROGRAM TO GENERATE ALL POSSIBLE STRINGS OUT
OF GIVEN INPUT:
C Program:generate.c
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int count;
void perm(char *ns,char * org,int l)
{
int i,til;
char *a;
printf(”\n s”,ns);
til=strlen(ns);
count++;
if(til>=l)
return;
a=(char *)malloc(strlen(ns)+2);
strcpy(a,ns);
a[til+1]=’\0’;
for(i=0;i¡strlen(org);i++)
{
a[til]=org[i];
perm(a,org,l);
}
free(a);
return; } int main()
{
char org[50];
int len;
printf(C̈HARACTERS : ”);scanf(”s”,org);
printf(M̈ax Length : ”);
scanf(”d”,&len);
perm(””,org,len);
printf(”\n d Permutations found\n”,count);
}
12