SE250:lab-3:sgha014

From Marks Wiki
Jump to navigation Jump to search

TASK 1...

int main(void){

	ArrayList xs;
	long i;
	long n=1000000;
	clock_t t;

	//initalize the array
	arraylist_init( &xs );
	
	// call clock
	t=clock();

	//insert elements into array 
	for(i=1; i<n; i++){
	arraylist_push( &xs, 1 );
	}

	// print out the time taken 
	printf("the time taken to add an element %ld number of times is %ld milliseconds\n", n, clock()-t);

}

the output was: the time taken to add an element1000000 number of times is 101 milliseconds

wen i changed n to a bigger number it takes a while for it to print out the time taken, and in some cases i sat there for ages and still nothing printed....when i made the n smaller it worked fine.

TASK 2...

changing the growth factor in the arraylist_put function..

i tried changing it to 0.5 and 0.75 and visual studio gave me a msg that said "lab3.exe has stopped working" so i tried it a few times and then decided to ask the tutor....who said that this is making the array SMALLER when the function is actually supposed to make it bigger...so thats why it wasnt working.....seems pretty stupid that i didnt realise that....moving along.... i tried it with the following growth factors: 1.5, 2.5, 3, 3.5, 4 the outputs were: 137 milliseconds, 116 milliseconds, 105 milliseconds, 95 milliseconds, 94 milliseconds

then i tried it for 7 to see what i would get.... the output was 97 milliseconds .....yea ok...


TASK 3...

changing the intial array size.... tried it with 26, 50, 100, 500, 1000 the outputs were 103 milliseconds, 102 milliseconds, 128 milliseconds, 97 milliseconds, 97 milliseconds

when i tried it with 2000 and 3000 i got a message saying "unable to locate component" the people next to me went up to 5million and it was still working....the code was basically the same....so i think i jst had a shit computer or something...??


TASK 4... i set the required capacity to 1000 and got an output of : no output...visial studio stopped working.....which the tutor said thats why task 2 was giving me starnge results wen i tried to go over 2000....i askd John and he told me 2 learn to use emacs coz he cant help me with visual studio....


TASK 5... with a growht factor of +1000 the output was: 2765 milliseconds

with +5000 the output was: 660 milliseconds

with +10000 the output was: 362 milliseconds

with +100000 the output was: 130 milliseconds

TASK 6...

replaced the arraylist_push with arraylist_put i tried it a few times and got no output....

when i made n smaller then i did get an output of : 33 milliseconds