Beruflich Dokumente
Kultur Dokumente
Semester
Subject
Analysis of Algorithms
Lectures
charge
Professor
In-
Practicals
Charge
Professor
In-
Laboratory number
Student Name
Sakharam S. Gawade
Roll Number
14102C2015
Grade
Subject Teachers
Signature
Experiment
Number
04
Experiment
Title
Resources
Apparatus
Used
Computer, Code::Blocks(IDE)
Objectives
Recursion, Round Robbin tennis tournament, Divide and
(Skill
Set/ Conquer Approach
Knowledge
tested/imparte
d)
Program:
/* Note:
n->
l
[ quad II
quad I ]
*/
#include<stdio.h>
int a[100][100],q[100];
void tennis(int st,int en)
{
int i,j,mid,k,temp;
if(st==en-1)//IF 2 players are left
{
a[1][1]=1;
a[1][2]=2;
a[2][1]=2;
a[2][2]=1;
return;
}
else
{
mid=(st+en)/2;
tennis(st,mid);// Keep on dividing until you get a 2 by 2 matrix i.e.
2 players
for(i=mid+1;i<=(mid+mid);i++)// will be used for solving the 1st
quadrant
{
q[i-mid]=i;
}
for(i=1;i<=mid;i++)
{
for(j=1;j<=mid;j++)//Solves the 3nd quadrant
{
a[i+mid][j]=a[i][j]+mid;
}
q[1]=temp;
for(j=mid+1;j<=(mid+mid);j++)//Solves the 4th quadrant
{
a[i+mid][j]=a[i][j]-mid;
}
}
}
}
void main()
{
int i,j,n;
printf("Enter the number of players[2^n]: ");
scanf("%d",&n);
tennis(1,n);
printf("\t
");
for(i=1;i<n;i++)
{
printf("D%d ",i);
}
for(i=1;i<=n;i++)
{
printf("\n Player %d ->",i);
for(j=2;j<=n;j++)
{
printf("%d
}
}
}
",a[i][j]);
Output run:
Conclusions:
Tennis tournament scheduling using round robin approach is an example of
divide and conquer. A simple 2 player schedule with some cyclic operations
can easily form a schedule for 2n players.