Correct and detailed answer please!
What is the runtime of the following functions in Big O notation?
void mystery1( FILE* input )
{
int temp;
int size;
int i=0;
int *array;
if( fscanf( input, "%d", &size ) != 1 )
{
exit(-1);
}
array = (int *) malloc( size*sizeof(int) );
if( array == NULL )
{
exit(-1);
}
while( fscanf( input, "%d", &temp ) == 1 && i
{
array[i] = temp;
i++;
}
while( size>1 )
{
size = size/2;
array[size/2] = array[size];
}
free(array);
}
void mystery2( FILE* input )
{
int temp;
int size;
int i=0, j=0;
int *array;
if( fscanf( input, "%d", &size ) != 1 )
{
exit(-1);
}
array = (int *) malloc( size*sizeof(int) );
if( array == NULL )
{
exit(-1);
}
while( fscanf( input, "%d", &temp ) == 1 && i
{
array[i] = temp;
i++;
}
i=0;
while( j
{
array[j] = array[i];
i++;
if( i>=size )
{
j++;
i=0;
}
}
free(array);
}
void mystery3( FILE* input )
{
int temp;
int size;
int n;
int i=0;
int *array;
if( fscanf( input, "%d", &size ) != 1 )
{
exit(-1);
}
array = (int *) malloc( size*sizeof(int) );
if( array == NULL )
{
exit(-1);
}
while( fscanf( input, "%d", &temp ) == 1 && i
{
array[i] = temp;
i++;
}
for( i=0; i
{
for( n=size-1; n>1; n/=1.01 )
{
array[n-1] = array[n];
}
}
free(array);
}