This action might not be possible to undo. Are you sure you want to continue?

# FAFL ASSIGNMENT NAME ROLL NO SEM : PRABHAKAR GOUDA : 35 : V CS&E ASSIGNMENT NO WEEK NO SECTION : 01,02,03 : 01 : B

1

Contents

0.1 0.2 Graphical representation of Daily Routine. SET THEORY . . . . . . . . . . . . . . . 0.2.1 Introduction . . . . . . . . . . . . . 0.2.2 Basic Operations with Sets . . . . . 0.2.3 Set-theoretic equalities . . . . . . . Graph Theory . . . . . . . . . . . . . . . . 0.3.1 Introduction . . . . . . . . . . . . . 0.3.2 Deﬁnitions . . . . . . . . . . . . . . 0.3.3 Graph Variations . . . . . . . . . . 0.3.4 Applications of Graph . . . . . . . 0.3.5 Isomorphism . . . . . . . . . . . . . 0.3.6 Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 . 4 . 4 . 4 . 6 . 6 . 6 . 7 . 8 . 8 . 9 . 10

0.3

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} ={t1,t2,t3,t4 .. . . tn} Diﬀerent input times. q0=W The initial state. F={S} We can represent the graph as:

Figure 1: graph

3

0.2

0.2.1

SET THEORY

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. Notation: we write names of sets like this: {0,1} The set containing 0 and 1 {Ted, {New York City}, 57} set containing just NYC, and the number 57 The set containing me, the

{0, 1, 2, ..} The set containing all the natural numbers (note: this set has inﬁnitely many members.) {x: x is an even number} The set containing the even numbers (i.e., {0, 2, 4, ...}) 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.

0.2.2

Union

Basic Operations with Sets

Let A and B be sets. The union of A and B is the set, denoted by A B, whose elements are exactly those sets belonging to A or belonging to B. For example, {0, 1, 2} ∪ {4, 5} = {0, 1, 2, 4, 5} Intersection Let A and B be sets. 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} Diﬀerence Let A and B be sets. The (relative) diﬀerence 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 diﬀerence 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 iﬀ 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.

0.2.3

**Set-theoretic equalities
**

which follow from the defA useful selection of these traditional names. These

There are a number of general laws about sets initions of set- theoretic operations, subsets, etc. is shown below. They are grouped under their equations below hold for any sets X, Y, Z: 1 Idempotent Laws (a) X ∪ X = X (b) 2 Commutative Laws (a) X ∪ Y = Y ∪ X (b) 3 Associative Laws (a) (X ∪ Y) ∪ Z = X ∪ (Y ∪ Z) (b) 4 Distributive Laws (a) X ∪ (Y ∩ Z) = (X ∪ Y) ∩ (X ∪ Z) (b) 5 Identity Laws (a) X ∪ φ = X (b) (c) X ∩ φ = φ (d) 6 Complement Laws (a) X ∪ X = U (c) X ∩ X = φ (d) 7 DeMorgans Laws (a) (X ∪ Y) = X ∩ Y (b) 8 Consistency Principle (a) X ⊆ Y iﬀ X ∪ Y = Y (b)

X∩X=X X∩Y=Y∩X (X ∩ Y) ∩Z = X (Y Z) X ∩ (Y ∪ Z) = (X ∩ Y) ∪ (X ∩ Z) X∪U=U X∩U=x (b)(X) = X X Y=X∩Y (X ∩ Y) = X ∪ Y X ⊆ Y iﬀ X ∩ Y = X

0.3

0.3.1

Graph Theory

Introduction

Informally, a graph is a bunch of dots connected by lines. Here is an example of a graph: 6

Sadly, this deﬁnition is not precise enough for mathematical discussion.

Figure 2: simple graph Formally, a graph is a pair of sets (V, E), where: V is a nonempty set whose elements are called vertices. E is a collection of twoelement subsets of V called edges. The vertices correspond to the dots in the picture, and the edges correspond to the lines. Thus, the dotsandlines diagram above is a pictorial representation of the graph (V, E) where: V = {A, B, C, D, E, F, G} E = {{A, B} , {A, C} , {B, D} , {C, D} , {C, E} , {E, F } , {E, G} } .

0.3.2

Deﬁnitions

A nuisance in ﬁrst learning graph theory is that there are so many deﬁnitions. 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 networks, 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 deﬁnition, 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 deﬁnitions here diﬀer subtly from deﬁnitions you see elsewhere. Usually, these diﬀerences do not matter. Hereafter, we use AB to denote an edge between vertices A and B rather than the set notation A, B. Note that AB and BA are the same edge, just as A, B and B, A are the same set. 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. Deleting some vertices or edges from a graph leaves a subgraph. Formally, a subgraph of G = (V, E) is a graph G = (V,E ) where V is a nonempty subset of V and E is a subset of E. Since a subgraph is itself a graph, the endpoints of every edge in E must be vertices in V.

0.3.3

Graph Variations

There are many variations on the basic notion of a graph. Three particularly common variations are described below. In a multigraph, there may be more than one edge be tween a pair of vertices. Here is an example:

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.

0.3.4

Applications of Graph

Graphs are the most useful mathematical objects in computer science. You can model an enormous number of realworld systems and phenomena using graphs. Once youve created such a model, you can tap the vast store of theorems about graphs to gain insight into the system youre modeling. Here are some practical situations where graphs arise: Data Structures Each vertex represents a data object. There is a directed edge from one object to another if the ﬁrst contains a pointer or reference to the second. Attraction Each vertex represents a person, and each edge represents a romantic attrac tion. The graph could be directed to model the unfortunate asymmetries. Airline Connections Each vertex represents an airport. If there is a direct ﬂight be tween two airports, then there is an edge between the corresponding vertices. These graphs often appear in airline magazines. 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 vertices, or add other ornaments that capture additional aspects of the phenomenon being modeled. For example, a graph of airline connections might have numbers on the edges to indicate the duration of the corresponding ﬂight. 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 :

Figure 4: regular graph

The empty graph has no edges at all.

0.3.5

Isomorphism

Two graphs that look the same might actually be diﬀerent 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 diﬀerent 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.

Figure 6: Non connected and Connected graphs

Lets put this observation in rigorous terms. A graph is connected if for every pair of vertices u and v, the graph contains a path with endpoints u and v as a subgraph. The graph on the left is not connected because there is no path from any of the top three vertices to either of the bottom two vertices. However, the graph on the right is connected, because there is a path between every pair of vertices. A maximal, connected subgraph is called a connected component. (By maximal, we mean that including any additional vertices would make the subgraph disconnected.) The graph on the left has two connected components, the triangle and the single edge. The graph on the right is entirely connected and thus has a single connected component.

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(CHARACTERS : ”);scanf(”s”,org); ¨ printf(Max Length : ”); scanf(”d”,&len); perm(””,org,len); printf(”\n d Permutations found\n”,count); }

12