You are on page 1of 2

Kevin Le

300053306
CSI3120 Assignment 2

Time Efficiency for Question 1:

Array Dimensions: 10x10


Subscript time:0.016911
Pointer time:0.023702

Array Dimensions: 20x20


Subscript time:0.074594
Pointer time:0.076124

Array Dimensions: 30x30


Subscript time:0.173316
Pointer time:0.204716

Array Dimensions: 40x40


Subscript time:0.419345
Pointer time:0.466891

Array Dimensions: 50x50


Subscript time:0.622506
Pointer time:0.712114

Array Dimensions: 100x100


Subscript time:2.314805
Pointer time:2.571001

Array Dimensions: 150x150


Subscript time:5.239171
Pointer time:5.255630

Array Dimensions: 175x175


Subscript time:7.058356
Pointer time:7.065016

Array Dimensions: 200x200


Subscript time:9.186760
Pointer time:10.406075

Array Dimensions: 250x250


Subscript time:15.092573
Pointer time:14.927994
Reliability for Subscript vs Pointer:
In terms of raw data, it’s hard to tell how reliable they are just based on runtimes. In general,
pointers should be more efficient than pointers. The skewed data could be due to the fact
that the data size is too small to notice or that the compiler might be not optimised or set up
correctly. You can see as you get to bigger numbers that the data starts to show the pointer
and subscript runtime margins being relatively close, and in the final run that the pointer
surpassed the subscript time. Although in general, pointers should be less reliable. This is
due to the fact that uninitialized pointers might cause segmentation faults. Additionally,
memory leaks may occur if dynamically allocated memory is not freed via the free() function.
If pointers are updated with incorrect values, it might lead to memory corruption too.

Question 3:

The advantage of static arrays is efficiency: No dynamic allocation or deallocation is


required. The disadvantage is that the storage for the array is fixed for the entire execution
time of the program. This compared to the array declared in the stack, initialising the static
array will be faster as it is initialised first before runtime compared to the stack array. A
heap-dynamic array is one in which the binding of subscript ranges and storage allocation is
dynamic and can change any number of times during the array’s lifetime. The advantage of
heap-dynamic arrays over the others is flexibility: Arrays can grow and shrink during
program execution as the need for space changes. The disadvantage is that allocation and
deallocation take longer and may happen many times during execution of the program.

It is clearly shown that static arrays have the highest compile time, then arrays declared
normally in the stack and finally heaps.This is due to the fact that heap memory is dynamic,
and so constant allocation and deallocation of memory takes time whereas static arrays
have fixed memory in terms of it’s memory size needs to be known at compile time
comparatively to the heap where the memory size is adjusted at runtime.

You might also like