Sie sind auf Seite 1von 5

DEPARTMENT OF COMPUTER ENGINEERING

Semester

S.E. Semester IV Computer Engineering

Subject

Analysis of Algorithms

Lectures
charge

Professor

In-

Practicals
Charge

Professor

In-

Laboratory number
Student Name

Prof. Sanjeev Dwivedi


Prof. Ashwin Ganesan
L07D

Sakharam S. Gawade

Roll Number

14102C2015

Grade

Subject Teachers
Signature

Experiment
Number

04

Experiment
Title

Constructing Tennis Tournament

Resources
Apparatus
Used

Computer, Code::Blocks(IDE)

Objectives
Recursion, Round Robbin tennis tournament, Divide and
(Skill
Set/ Conquer Approach
Knowledge
tested/imparte
d)

Description of the experiment:


The technique of divide and conquer has widespread applicability not only in
algrithm design but in designing circuits, constructing mathematical proofs
and in another walks of life. We give one example of as an illustration. A

practical problem encountered by the management of a tennis club is


theorganization of a tennis tournament for the club members. The
tournament participants aresplit into different series: in each series, every
player plays once a week with adifferent opponent in a round robin
tournament. All matches are subject to a time limitcorresponding to one
hour. All the series share the same pool of courts, whose weeklyavailability is
predefined. In addition, the players have their own availabilityconstraints.
Given the courts and players availability, the objective is to schedule
thetournament with no violation of the constraints or, more realistically, in
order tomaximize the number of feasible matches. This problem can be
formulated as a maximummatching problem, with the additional constraint
that each player must play just once aweek. It can also be modeled as a
maximum clique problem. A twostep heuristicprocedure is proposed to solve
the problem: first, the round robin tournaments ofeach series are generated,
then the matches of each tournament are assignedto the available courts for
every week by means of a local search procedure. The procedurehas been
succesfully implemented and is currently used by the tennis club.

Program:
/* Note:
n->
l

[ quad II

quad I ]

[ quad III quad IV ]

*/

#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;
}

for(j=mid+1;j<=(mid+mid);j++)//Solves the 1st quadrant


{
a[i][j]=q[j-mid];
}
temp=q[mid];
for(k=mid-1;k>=1;k--)// solves every row of 1st quadrant
{
q[k+1]=q[k];
}

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.

Das könnte Ihnen auch gefallen