MinMax Algorithm using c++

MinMax Algorithm using c++

Description:

Minimax is a decision rule used in decision theory, game theory, statistics and philosophy for minimizing the possible loss for a worst case (maximum loss) scenario. When dealing with gains, it is referred to as "maximin" - to maximize the minimum gain. Originally formulated for two-player zero-sum game theory, covering both the cases where players take alternate moves and those where they make simultaneous moves, it has also been extended to more complex games and to general decision-making in the presence of uncertainty.


Program: 
#include < stdio.h >
#include < conio.h >

int a[]={22,13,-47,-8,15,60,17,91,47};

void maxmin(int i,int j,int *max,int *min)
{
int mid,max1,min1;

if(i==j)
*max=*min=a[i];
else if(i==j-1)
{
if(a[i] < a[j])
{
*max=a[j];
*min=a[i];
}
else
{
*max=a[i];
*min=a[j];
}
}
else
{
mid=(i+j)/2;
maxmin(i,mid,max,min);
maxmin(mid+1,j,&max1,&min1);

if(*max < max1)
*max=max1;
if(*min > min1)
*min=min1;
}
}
void main() {
clrscr();
int max=0,min=0;
maxmin(0,8,&max,&min);
printf("\n\t The Maximum Value is : %d ",max);
printf("\n\t The Minimum Value is : %d ",min);
getch();
}

Comments

Popular posts from this blog

How to create a custom form in wordpress

My new Jquery Plugin name is krDailog