Name-Subha Sankar Chakraborty Name of The Assignment:Topics On Algorithm Assignment No-1 M.Tech (Cse) 1 Year Binary Search Tree Operations
Name-Subha Sankar Chakraborty Name of The Assignment:Topics On Algorithm Assignment No-1 M.Tech (Cse) 1 Year Binary Search Tree Operations
int x,y,z,num;
root=(struct node *)malloc(sizeof(struct node));
printf("Enter data of root: ");
scanf("%d",&num);
root->data=num;
root->right=root->left=NULL;
do
{
printf("Press 1 for preorder\n");
printf("Press 2 for postorder\n");
printf("Press 3 for inorder\n");
printf("Press 4 for insert\n");
printf("Press 5 for Exit\n");
scanf("%d",&x);
if(x==1)
{
preorder(root);
}
else if(x==2)
{
postorder(root);
}
else if(x==3)
{
inorder(root);
}
else if(x==4)
{
printf("\nEnter the data for inserting: ");
scanf("%d",&y);
insert(root,y);
}
else if(x==5)
{
exit(0);
}
else
{
printf("Invalid choice");
}
printf("\nPress 1 for continue\n");
scanf("%d",&z);
}
while(z==1);
getch();
}
Algorithm
MIN_DISTANCE_LENGTH INFINITY
for each cities C in the graph G
for each cities C_N in the graph G such that C and C_N are different
mark all cities unvisited
mark C as visited
for staring cities as C and succeeding cities as C_N, find Cost
such that path staring from C_N in that Cost is minimum
Pseudo Code
Input : Number of cities n and array of costs c(i,j) i,j=1,..n (We begin from city number 1)
Output:Vector of cities and total cost.
(* starting values *)
C=0
cost=0
visits=0
e=1 (*e=pointer of the visited city)
(* determination of round and cost)
for r=1 to n-1 do
choose of pointer j with
minimum=c(e,j)=min{c(e,k);visits(k)=0 and k=1,..,n}
cost=cost+minimum
e=j
C(r)=j
end r-loop
C(n)=1
cost=cost+c(e,1)
We can find situations in which the TSP algorithm doesnt give the best solution. We can also
succeed on improving the algorithm. For example we can apply the algorithm t times for t
different cities and keep the best round every time. We can also unbend the greeding in such a
way to reduce the algorithm problem that is there is no room for choosing cheep sides at the end
of algorithm because the cheapest sides have been exhausted.