WHAT IS ALGORITHM
Algorithm is a step-by-step procedure, which defines a set of instructions to be
executed in a certain order to get the desired output. Algorithms are generally created
independent of underlying languages, i.e. an algorithm can be implemented in more
than one programming language.
CATEGORIES OF ALGORITHMS
Search − Algorithm to search an item in a data structure.
Sort − Algorithm to sort items in a certain order.
Insert − Algorithm to insert item in a data structure.
Update − Algorithm to update an existing item in a data structure.
Delete − Algorithm to delete an existing item from a data structure.
CHARACTERISTICS OF AN ALGORITHM
Not all procedures can be called an algorithm. An algorithm should have the
following characteristics −
Unambiguous − Algorithm should be clear and unambiguous. Each of its
steps (or phases), and their inputs/outputs should be clear and must lead to
only one meaning.
Input − An algorithm should have 0 or more well-defined inputs.
Output − an algorithm should have 1 or more well-defined outputs, and
should match the desired output.
Finiteness − Algorithms must terminate after a finite number of steps.
Feasibility − should be feasible with the available resources.
Independent − an algorithm should have step-by-step directions, which
should be independent of any programming code.
1|Page
PERFORMANCE ANALYSIS
In theoretical analysis of algorithms, it is common to estimate their complexity in
the asymptotic sense, i.e., to estimate the complexity function for arbitrarily large
input. The term "analysis of algorithms" was coined by Donald Knuth.
Algorithm analysis is an important part of computational complexity theory, which
provides theoretical estimation for the required resources of an algorithm to solve a
specific computational problem. Most algorithms are designed to work with inputs
of arbitrary length. Analysis of algorithms is the determination of the amount of time
and space resources required to execute it.
Generally, we perform the following types of analysis −
Worst-case − The maximum number of steps taken on any instance of size a.
Best-case − The minimum number of steps taken on any instance of size a.
Average case − An average number of steps taken on any instance of size a.
2|Page
SPACE COMPLEXITY
Space complexity is the amount of memory used by the algorithm (including the
input values to the algorithm) to execute and produce the result.
Sometime Auxiliary Space is confused with Space Complexity. But Auxiliary Space
is the extra space or the temporary space used by the algorithm during its execution.
Space Complexity = Auxiliary Space + Input space
Memory Usage during program execution
1. Instruction Space is used to save compiled instruction in the memory.
2. Environmental Stack is used to storing the addresses while a module calls
another module or functions during execution.
3. Data space is used to store data, variables, and constants which are stored by
the program and it is updated during execution.
3|Page
TIME COMPLEXITY
Time complexity of an algorithm signifies the total time required by the program to
run till its completion.
Time complexity of an algorithm signifies the total time required by the program to
run till its completion. Time Complexity is most commonly estimated by counting
the number of elementary steps performed by any algorithm to finish execution. Like
in the example above, for the first code the loop will run n number of times, so the
time complexity will be n at least and as the value of n will increase the time taken
will also increase. While for the second code, time complexity is constant, because it
will never be dependent on the value of n, it will always give the result in 1 step.
And since the algorithm's performance may vary with different types of input data,
hence for an algorithm we usually use the worst-case Time complexity of an
algorithm because that is the maximum time taken for any input size.
Calculating time complexity: to calculate time complexity here is some common
examples to understand
For (i=0; i<N; i++)
Statement;
The time complexity for the above algorithm will be linear. The running time of loop
is directly proportional to N.
4|Page
ASYMPTOTIC NOTATIONS
The purpose of asymptotic notation is to estimate how long a program will run and
helps in comparing the efficiency of different algorithms. It is used to measure the
growth rate of an algorithm. The asymptotic notations are basically of three types:
1. Big Oh
2. Big Omega
3. Big Theta
Big oh (O-Notation): this notation is used to denote asymptotic upper bound. It is a
notation for the worst case. It takes maximum time by an algorithm to run its
completion.
O(g(n)) = {f(n) : there exist positive constants c and n 0 such that 0<=f(n)<=c*g(n) for
all n>=n0
Ω-Notation (Omega Notation): To denote the lower bound, we use Ω-notation. It is
a notation for the best case. It takes least time by an algorithm to run its completion.
Ω(g(n)) = {f(n) : there exist positive constants c and n 0 such that 0<=c*g(n) <=f(n)
for all n>=n0
Θ-Notation (Theta Notation): to denote asymptotic tight bound, we use Θ notation.
Theta notation is used to define the average bound of an algorithm. It takes average
time to run its completion.
Θ(g(n)) = {f(n) : there exist positive constants c 1,c2 and n0 such that 0<=c1*g(n)
<=f(n) <=c2 *g(n) for all n>=n0
5|Page
COMPUTER GRAPHICS
Computer Graphics is the creation of pictures with the help of a computer. The end
product of the computer graphics is a picture it may be a business graph, drawing,
and engineering.
Definition of Computer Graphics:
It is the use of computers to create and manipulate pictures on a display device. It
comprises of software techniques to create, store, modify, represents pictures.
Why computer graphics used?
Suppose a shoe manufacturing company want to show the sale of shoes for five
years. For this vast amount of information is to store. So a lot of time and memory
will be needed. This method will be tough to understand by a common man. In this
situation graphics is a better alternative. Graphics tools are charts and graphs. Using
graphs, data can be represented in pictorial form. A picture can be understood easily
just with a single look.
Interactive computer graphics work using the concept of two-way communication
between computer users. The computer will receive signals from the input device,
and the picture is modified accordingly. Picture will be changed quickly when we
apply command.
Application of Computer Graphics
6|Page
1. Education and Training: Computer-generated model of the physical, financial
and economic system is often used as educational aids. Model of physical systems,
physiological system, population trends or equipment can help trainees to understand
the operation of the system.
For some training applications, particular systems are designed. For example: Flight
Simulator.
2. Use in Biology: Molecular biologist can display a picture of molecules and gain
insight into their structure with the help of computer graphics.
3. Computer-Generated Maps: Town planners and transportation engineers can use
computer-generated maps which display data useful to them in their planning work.
4. Architect: Architect can explore an alternative solution to design problems at an
interactive graphics terminal. In this way, they can test many more solutions that
would not be possible without the computer.
5. Presentation Graphics: Example of presentation Graphics are bar charts, line
graphs, pie charts and other displays showing relationships between multiple
parameters.
6. Entertainment: Computer Graphics are now commonly used in making motion
pictures, music videos and television shows.
7. Visualization: It is used for visualization of scientists, engineers, medical
personnel, business analysts for the study of a large amount of information.
Advantages:
Fuel Saving
7|Page
Safety
Ability to familiarize the training with a large number of the world's airports.
Example of Computer Graphics Packages:
LOGO
COREL DRAW
AUTO CAD
3D STUDIO
CORE
GKS (Graphics Kernel System)
CAM (Computer Graphics Metafile)
INBUILT GRAPHICAL FUNCTIONS
8|Page
BAR (): The header file graphics.h contains bar() function which is used to draw
a 2 dimensional, rectangle filled in bar.
Syntax: void bar( int left, int top, int right, int bottom);
Example: bar(150,150,190,350);
CIRCLE(): To draw the circle.
Syntax: void circle(x-axis,y-axis,radius);
example: circle(20,20,5);
CLEARDEVICE():To clear the graphical screen.
Syntax: void cleardevice(void);
Example: cleardevice();
CLOSEGRAPH(): Shut down the graphical screen and return back to the text
mode.
Syntax: void closegraph();
Example: closegraph();
INITGRAPH(): Initialize the graphical screen.
Syntax: void initgraph(int *graphdriver, int *graphmode, char *pathtodriver);
Example: initgraph(&gd,&gm,””);
OUTTEXTXY(): Sends a string to a specified location.
Syntax: void outextxy(int x,int y,”string name”);
Example:outtextxy(50,50,”hello how are you”);
RECTANGLE(): To draw a rectangle.
Syntax: void rectangle(int left, int top, int right, int bottom);
Example: rectangle(50,50,200,250);
9|Page
SETCOLOR(): To sets the color of the text.
Syntax: void setcolor(int color);
Example: setcolor(5);
SETFILLSTYLE(): Sets the fill pattern and color.
Syntax: void setfillstyle(int pattern, int color);
Example: setfillstyle(SOLID_LINE,BLUE);
LINE(): To draw a line in graphical mode.
Syntax: void line(int x0 , int y0 , int x1 , int y1);
Example: line(20,40,50,40);
SETBKCOLOR(): To set the background color of the screen in graphical mode.
Syntax: void setbkcolor(int color);
Example: setbkcolor(5);
KRUSKAL’S ALGORITHM
10 | P a g e
Kruskal's algorithm is a minimum spanning tree algorithm that takes a graph as
input and finds the subset of the edges of that graph which
form a tree that includes every vertex
has the minimum sum of weights among all the trees that can be formed from the
graph
Any minimum spanning tree algorithm revolves around checking if adding an edge
creates a loop or not.
The most common way to find this out is an algorithm called Union FInd. The
Union-Find algorithm divides the vertices into clusters and allows us to check if two
vertices belong to the same cluster or not and hence decide whether adding an edge
creates a cycle.
How Kruskal’s Algorithm Works?
It falls under a class of algorithms called greedy algorithms which find the local
optimum in the hopes of finding a global optimum.
We start from the edges with the lowest weight and keep adding edges until we we
reach our goal.
The steps for implementing Kruskal's algorithm are as follows:
Sort all the edges from low weight to high
Take the edge with the lowest weight and add it to the spanning tree. If adding the
edge created a cycle, then reject this edge.
Keep adding edges until we reach all vertices.
11 | P a g e
Example Of Kruskal’s Algorithm :
Now, let us learn some programming aspects of
kruskal’s algorithm.
Algorithm
Kruskal (E,Cost,n,t)
//G is a graph with n vertices and Edges.Cost(u,v) is the cost of edge(u,v).t is a set
that 12 | P a g e
//include min-cost spanning tree.Final Minimum cost is returned.
{
Complexity Analysis of Kruskal’s Algorithm :
Kruskal's algorithm can be shown to run in O(E log E) time, or
equivalently, O(E log V) time, where E is the number of edges in the graph and V is
the number of vertices, all with simple data structures. These running times are
equivalent because:
E is at most {\displaystyle V^{2}} and {\displaystyle \log
V^{2}=2\log V} is {\displaystyle O(\log V)} .
Each isolated vertex is a separate component of the minimum spanning forest.
If we ignore isolated vertices we obtain V ≤ 2E, so log V is {\displaystyle O(\log
E)} .
We can achieve this bound as follows: first sort the edges by weight using
a comparison sort in O(E log E) time; this allows the step "remove an edge with
minimum weight from S" to operate in constant time. Next, we use a disjoint-set data
structure to keep track of which vertices are in which components. We need to
perform O(V) operations, as in each iteration we connect a vertex to the spanning
tree, two 'find' operations and possibly one union for each edge. Even a simple
disjoint-set data structure such as disjoint-set forests with union by rank can perform
O(V) operations in O(V log V) time. Thus the total time is O(E log E) = O(E log V).
Provided that the edges are either already sorted or can be sorted in linear time (for
example with counting sort or radix sort), the algorithm can use a more
sophisticated disjoint-set data structure to run in O(E α(V)) time, where α is the
extremely slowly growing inverse of the single-valued Ackermann function.
13 | P a g e
SOFTWARE REQUIREMENT SPECIFICATIONS (SRS) :
MINIMUM HARDWARE REQUIREMENT:
RAM 60 MB
HD 20MB
PROCESSOR PANTIUM 1
I/0 DEVICES KEYBOARD,MOUSE,VGA
MONITER
MINIMUM SOFTWARE REQUIREMENT:
TURBO C
WINDOWS 3.0
WINDOWS XP OR HIGHER OPERATING SYSTEM
14 | P a g e
Coding
15 | P a g e
SOURCE CODE
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void a1();
void a2();
void a3();
void a4();
void a5();
void a6();
void a7();
void a8();
void a9();
void a10();
void a11();
void a12();
void a13();
int i,j,k,a,b,u,v,n,ne=1;
int min,mincost=0,cost[9][9],parent[9];
int find(int);
int uni(int,int);
void main()
{
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
a1() ;
16 | P a g e
a2() ;
getch();
closegraph();
}
void a1()
{
int gd=DETECT,gm,i,xmax,iii[20],jjj[20],ccc[20],ymax,n,m,k,j,c;
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
//first screen
setcolor(4);
setbkcolor(CYAN);
setlinestyle(3,0,3);
line(0,0,639,0);
line(639,0,639,497);
line(639,479,0,479);
line(0,479,0,0);
settextstyle(10,0,3);
outtextxy(100,40,"THE PROJECT IS BASED");
outtextxy(290,80,"ON");
outtextxy(130,120,"KRUSKAL'S ALGORITHM");
settextstyle(10,0,3);
outtextxy(101,41,"THE PROJECT IS BASED");
outtextxy(291,81,"ON");
outtextxy(131,121,"KRUSKAL'S ALGORITHM");
settextstyle(10,0,3);
outtextxy(102,42,"THE PROJECT IS BASED");
outtextxy(292,82,"ON");
17 | P a g e
18 | P a g e
outtextxy(132,121,"KRUSKAL'S ALGORITHM");
settextstyle(1,0,3);
outtextxy(10,320,"SUBMITTED TO:");
settextstyle(1,0,2);
outtextxy(10,365,"Mrs.PRABHJEET KAUR");
settextstyle(1,0,3);
outtextxy(360,320,"SUBMITTED BY:");
settextstyle(1,0,2);
outtextxy(360,365,"KULJEET");
outtextxy(360,395,"SHALLY");
outtextxy(350,450,"Press any key to continue....");
getch();
closegraph();
}
void a2()
{
int gd=DETECT,gm,d1;
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
//second screen
setbkcolor(WHITE);
setcolor(4);
setlinestyle(3,0,3);
line(0,0,639,0);
line(639,0,639,497);
line(639,479,0,479);
line(0,479,0,0);
settextstyle(1,0,1);
19 | P a g e
20 | P a g e
setcolor(3);
outtextxy(200,150,"Press 1 : For Graphic Mode");
outtextxy(200,170,"Press 2 : For Non-Graphic Mode");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t");
scanf("%d",&d1);
switch(d1)
{
case 1:
a3() ;
a4() ;
a5() ;
a6() ;
a7() ;
a8() ;
a9() ;
a10() ;
break;
case 2:
a11() ;
a12() ;
break;
default:
a13() ;
break;
}
getch();
closegraph();
}
21 | P a g e
22 | P a g e
void a3()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
//third screen
setbkcolor(WHITE);
setcolor(4);
setlinestyle(3,0,3);
line(0,0,639,0);
line(639,0,639,497);
line(639,479,0,479);
line(0,479,0,0);
settextstyle(4,0,4);
setcolor(3);
outtextxy(180,10,"Kruskal's Algorithm");
setcolor(3);
line(180,50,450,50);
settextstyle(1,0,1);
setcolor(4);
outtextxy(20,70,"This algothrim for finding the MST and its use greedy approach.");
outtextxy(20,90,"This algorithm treats the graph as a forest and every vertex it");
outtextxy(20,112,"has as an individual tree.It builds the spanning tree by adding");
outtextxy(20,132,"edges one by one into a growing spanning tree and in each");
outtextxy(20,152,"iteraton it finds an edge which has least weight and add it to");
outtextxy(20,172,"the growing spanning tree.That is,A tree connects to another if");
outtextxy(20,192,"it has the least cost among all available options and does not");
outtextxy(20,212,"violate MST properties.This could be done using DFS which starts");
outtextxy(20,232,"from the first vertex,then check if the second vertex is visited");
23 | P a g e
24 | P a g e
outtextxy(20,252,"or not.But DFS will make time complexity large as it has an");
outtextxy(20,272,"order of O(V+E).The best solution is disjoint sets.");
outtextxy(20,296,"The operations an disjoint sets are :-");
setcolor(8);
line(20,325,370,325);
settextstyle(1,0,1);
setcolor(3);
outtextxy(20,332,"Make_set(v):");
settextstyle(1,0,1);
setcolor(4);
outtextxy(134,332,"create a new set whose only member is pointed to v.");
settextstyle(1,0,1);
setcolor(3);
outtextxy(20,353,"Find_set(v):");
settextstyle(1,0,1);
setcolor(4);
outtextxy(134,353,"returns a pointer to the set containing v.");
settextstyle(1,0,1);
setcolor(3);
outtextxy(20,373,"Union(u,v):");
settextstyle(1,0,1);
setcolor(4);
outtextxy(134,373,"unites the dynamic sets that contain u and v into a");
outtextxy(134,393,"new set that is union of these two sets.");
setcolor(BLUE);
settextstyle(3,0,1);
outtextxy(360,430,"Press any key to continue.....");
getch();
25 | P a g e
26 | P a g e
closegraph();
}
void a4()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
//fourth screen
setbkcolor(WHITE);
setcolor(4);
setlinestyle(3,0,3);
line(0,0,639,0);
line(639,0,639,497);
line(639,479,0,479);
line(0,479,0,0);
settextstyle(1,0,1);
setcolor(3);
outtextxy(20,30,"No. Of Vertexs are :");
setcolor(4);
outtextxy(202,30,"6");
setcolor(3);
outtextxy(20,60,"No. Of Edges are :");
setcolor(4);
outtextxy(202,60,"10");
setcolor(3);
circle(300,140,17); //a
circle(230,220,17); //b
circle(370,220,17); //d
circle(300,300,17); //c
27 | P a g e
28 | P a g e
circle(230,380,17); //e
circle(370,380,17); //f
settextstyle(1,0,1);
setcolor(4);
outtextxy(295,130,"A");
outtextxy(225,210,"B");
outtextxy(365,208,"D");
outtextxy(295,290,"C");
outtextxy(225,370,"E");
outtextxy(367,370,"F");
setlinestyle(SOLID_LINE,1,1);
//line(315,145,375,205);
//line(285,145,225,205);
line(297,157,360,205); //a to d
line(297,157,240,205); //a to b
line(240,233,285,292); // b to c
line(360,233,315,290); //c to d
line(297,157,297,285); //a to c
line(230,238,230,365); //b to e
line(370,238,370,365); //d to f
line(245,380,352,380); // e to f
line(289,316,240,369); // c to e
line(312,313,359,368); //c to f
settextstyle(1,0,1);
setcolor(5);
outtextxy(250,165,"6");
outtextxy(335,165,"5");
outtextxy(300,220,"1");
29 | P a g e
30 | P a g e
outtextxy(265,245,"5");
outtextxy(325,245,"5");
outtextxy(220,300,"3");
outtextxy(380,300,"2");
outtextxy(300,376,"6");
outtextxy(330,320,"4");
outtextxy(265,320,"5");
getch();
closegraph();
}
void a5()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
//thrid screen
setbkcolor(WHITE);
setcolor(4);
setlinestyle(3,0,3);
line(0,0,639,0);
line(639,0,639,497);
line(639,479,0,479);
line(0,479,0,0);
settextstyle(1,0,1);
setcolor(4);
outtextxy(20,60,"Initial Formation Of The Graph Is :");
setcolor(3);
circle(300,140,17); //a
circle(230,220,17); //b
31 | P a g e
32 | P a g e
circle(370,220,17); //d
circle(300,300,17); //c
circle(230,380,17); //e
circle(370,380,17); //f
settextstyle(1,0,1);
setcolor(4);
outtextxy(295,130,"A");
outtextxy(225,210,"B");
outtextxy(365,208,"D");
outtextxy(295,290,"C");
outtextxy(225,370,"E");
outtextxy(367,370,"F");
getch();
closegraph();
}
void a6()
{
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
//thrid screen
setbkcolor(WHITE);
setcolor(4);
setlinestyle(3,0,3);
line(0,0,639,0);
line(639,0,639,497);
line(639,479,0,479);
line(0,479,0,0);
33 | P a g e
34 | P a g e
settextstyle(1,0,1);
setcolor(4);
outtextxy(20,30,"From graph select the edge which have");
setcolor(4);
outtextxy(20,60,"the minimum weight=1 and (A,C) is selected");
setcolor(3);
circle(300,140,17); //a
circle(230,220,17); //b
circle(370,220,17); //d
circle(300,300,17); //c
circle(230,380,17); //e
circle(370,380,17); //f
settextstyle(1,0,1);
setcolor(4);
outtextxy(295,130,"A");
outtextxy(225,210,"B");
outtextxy(365,208,"D");
outtextxy(295,290,"C");
outtextxy(225,370,"E");
outtextxy(367,370,"F");
setlinestyle(SOLID_LINE,1,1);
line(297,157,297,285); //a to c
getch();
closegraph();
}
void a7()
{
int gd=DETECT,gm;
35 | P a g e
36 | P a g e
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
//thrid screen
setbkcolor(WHITE);
setcolor(4);
setlinestyle(3,0,3);
line(0,0,639,0);
line(639,0,639,497);
line(639,479,0,479);
line(0,479,0,0);
settextstyle(1,0,1);
setcolor(4);
outtextxy(20,30,"From graph select the edge which have");
setcolor(4);
outtextxy(20,60,"the minimum weight=2 and (D,F) is selected");
setcolor(3);
circle(300,140,17); //a
circle(230,220,17); //b
circle(370,220,17); //d
circle(300,300,17); //c
circle(230,380,17); //e
circle(370,380,17); //f
settextstyle(1,0,1);
setcolor(4);
outtextxy(295,130,"A");
outtextxy(225,210,"B");
outtextxy(365,208,"D");
outtextxy(295,290,"C");
outtextxy(225,370,"E");
37 | P a g e
38 | P a g e
outtextxy(367,370,"F");
setlinestyle(SOLID_LINE,1,1);
line(297,157,297,285); //a to c
line(370,238,370,365); //d to f
getch();
closegraph();
}
void a8()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
//thrid screen
setbkcolor(WHITE);
setcolor(4);
setlinestyle(3,0,3);
line(0,0,639,0);
line(639,0,639,497);
line(639,479,0,479);
line(0,479,0,0);
settextstyle(1,0,1);
setcolor(4);
outtextxy(20,30,"From graph select the edge which have");
setcolor(4);
outtextxy(20,60,"the minimum weight=3 and (B,E) is selected");
setcolor(3);
circle(300,140,17); //a
circle(230,220,17); //b
circle(370,220,17); //d
39 | P a g e
40 | P a g e
circle(300,300,17); //c
circle(230,380,17); //e
circle(370,380,17); //f
settextstyle(1,0,1);
setcolor(4);
outtextxy(295,130,"A");
outtextxy(225,210,"B");
outtextxy(365,208,"D");
outtextxy(295,290,"C");
outtextxy(225,370,"E");
outtextxy(367,370,"F");
setlinestyle(SOLID_LINE,1,1);
line(297,157,297,285); //a to c
line(230,238,230,365); //b to e
line(370,238,370,365); //d to f
getch();
closegraph();
}
void a9()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
//thrid screen
setbkcolor(WHITE);
setcolor(4);
setlinestyle(3,0,3);
line(0,0,639,0);
line(639,0,639,497);
41 | P a g e
42 | P a g e
line(639,479,0,479);
line(0,479,0,0);
settextstyle(1,0,1);
setcolor(4);
outtextxy(20,30,"From graph select the edge which have");
setcolor(4);
outtextxy(20,60,"the minimum weight=4 and (C,F) is selected");
setcolor(3);
circle(300,140,17); //a
circle(230,220,17); //b
circle(370,220,17); //d
circle(300,300,17); //c
circle(230,380,17); //e
circle(370,380,17); //f
settextstyle(1,0,1);
setcolor(4);
outtextxy(295,130,"A");
outtextxy(225,210,"B");
outtextxy(365,208,"D");
outtextxy(295,290,"C");
outtextxy(225,370,"E");
outtextxy(367,370,"F");
setlinestyle(SOLID_LINE,1,1);
line(297,157,297,285); //a to c
line(230,238,230,365); //b to e
line(370,238,370,365); //d to f
line(312,313,359,368); //c to f
settextstyle(1,0,1);
43 | P a g e
44 | P a g e
setcolor(4);
outtextxy(20,410,"(A,D),(C,D)");
outtextxy(20,430,"are not selected because they create cycle");
getch();
closegraph();
}
void a10()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
//thrid screen
setbkcolor(WHITE);
setcolor(4);
setlinestyle(3,0,3);
line(0,0,639,0);
line(639,0,639,497);
line(639,479,0,479);
line(0,479,0,0);
settextstyle(1,0,1);
setcolor(4);
outtextxy(20,30,"From graph select the edge which have");
setcolor(4);
outtextxy(20,60,"the minimum weight=5 and (B,C) is selected");
setcolor(3);
circle(300,140,17); //a
circle(230,220,17); //b
circle(370,220,17); //d
circle(300,300,17); //c
45 | P a g e
46 | P a g e
circle(230,380,17); //e
circle(370,380,17); //f
settextstyle(1,0,1);
setcolor(4);
outtextxy(295,130,"A");
outtextxy(225,210,"B");
outtextxy(365,208,"D");
outtextxy(295,290,"C");
outtextxy(225,370,"E");
outtextxy(367,370,"F");
setlinestyle(SOLID_LINE,1,1);
line(240,233,285,292); // b to c
line(297,157,297,285); //a to c
line(230,238,230,365); //b to e
line(370,238,370,365); //d to f
line(312,313,359,368); //c to f
settextstyle(1,0,1);
setcolor(4);
outtextxy(20,410,"(A,B),(A,D),(C,E),(C,D),(E,F)");
outtextxy(20,430,"are not selected because they create cycle");
getch();
closegraph();
}
void a11()
{
int gd =DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
47 | P a g e
48 | P a g e
// First Screen
cleardevice();
settextstyle(10,0,7);
setcolor(CYAN);
outtextxy(80,5,"WELCOME");
outtextxy(100,80,"......... ");
settextstyle(3,0,4);
outtextxy(55,270,"Loading ........Please Wait");
setcolor(BLUE);
rectangle(55,305,505,325);
for(i=55;i<=405;i++)
{
rectangle(i,305,i+100,325);
//delay(10);
}
//Third Screen
cleardevice();
settextstyle(4,0,1);
gotoxy(5,5);
printf("\n\tImplementation of Kruskal's algorithm\n");
printf("\nEnter the no. of vertices:");
scanf("%d",&n);
printf("\nEnter the cost adjacency matrix:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&cost[i][j]);
49 | P a g e
50 | P a g e
if(cost[i][j]==0)
cost[i][j]=999;
}
}
printf("The edges of Minimum Cost Spanning Tree are\n");
while(ne < n)
{
for(i=1,min=999;i<=n;i++)
{
for(j=1;j <= n;j++)
{
if(cost[i][j] < min)
{
min=cost[i][j];
a=u=i;
b=v=j;
}
}
}
u=find(u);
v=find(v);
if(uni(u,v))
{
printf("%d edge (%d,%d) =%d\n",ne++,a,b,min);
mincost +=min;
}
cost[a][b]=cost[b][a]=999;
}
51 | P a g e
52 | P a g e
printf("\n\tMinimum cost = %d\n",mincost);
getch();
}
int find(int i)
{
while(parent[i])
i=parent[i];
return i;
}
int uni(int i,int j)
{
if(i!=j)
{
parent[j]=i;
return 1;
}
return 0;
}
void a12()
{
int gd =DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
settextstyle(3,0,9);
setcolor(15);
outtextxy(60,120,"--------------------");
outtextxy(70,170,"THANK YOU");
outtextxy(60,220,"----------");
53 | P a g e
54 | P a g e
getch();
closegraph();
}
void a13()
{
int gd =DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
setbkcolor(WHITE);
setcolor(4);
setlinestyle(3,0,3);
line(0,0,639,0);
line(639,0,639,497);
line(639,479,0,479);
line(0,479,0,0);
settextstyle(1,0,9);
setcolor(4);
outtextxy(200,170,"Sorry");
getch();
closegraph();
}
55 | P a g e
SNAPSHOT
56 | P a g e
FRONT PAGE :-
SECOND PAGE :-
Graphical Mode :-
57 | P a g e
58 | P a g e
59 | P a g e
60 | P a g e
Non-graphical mode :-
61 | P a g e
62 | P a g e
Default:-
63 | P a g e
BIBLIOGRAPHY
Fundamentals of algorithm(By Sartaj Sahni)
Computer graphics(By Hearn and Baker)
www.CGW.com
www.programmingsimplified.com
64 | P a g e