SE250:lab-3:rthu009

From Marks Wiki
Revision as of 05:19, 3 November 2008 by Mark (Sọ̀rọ̀ | contribs) (11 revision(s))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Lab 3 Rthu009

Task 1

In this task it required for me to push the array list by adding numbers to the arraylist_push function. I have set up loops which increment the value one by one and then adding it to the array push list.

#include <stdio.h>
#include "arraylist.h"
#include <stdlib.h>
#include <time.h>
.
int main (){
.	int i;
.	clock_t start, finish;
.   double  duration;
.	ArrayList arr;
.	arraylist_init( &arr );
.
.
.	start = clock();
.	for( i=0; i <= 100000000; i++ ){
.		arraylist_push(&arr, i );
.
.	}
finish = clock();
.
.
duration = (double)(finish - start) / CLOCKS_PER_SEC;
.  
.  printf("Time takes to push 100000000 numbers\n");
.  printf( "%2.1f seconds\n", duration );
. 
.
}


As a result of adding 100000000 numbers to the array_push list it has taken 15.1 seconds to complete the task. I have tried to increase the values to 1000000000 and the program ran our of memory and program aborted. This can be because the malloc function couldn’t generate any more space for that required for the program to execute.

Output

Time takes to push 100000000 numbers

15.1 seconds


Task 2

In this task the growth factor has been increases by multiples of 2. The result shows the how increasing growth can have a significant effect on the time.

Growth factor 	Time taken
2	          9.6
4	          9.9
6	          8.9
8	          9.1
10	          8.5
12	          --
14	          8.4
16	          9.2
18	          --
20	          --


The dash lines shows the area where the program crashed trying to allocate more memory space.


Task 3

results of increasing the array size

Array size	Time (s)
    16	          9.1
    17	          9.6
    18	          9.4
    19	          9.8
    20	          9.9
    25	          8.9
    30	          9.6
    40	          9.6
    41            9.9

There isn't any significant change in the time there for the i assume the increasing array size around this range wouldn't make much different.