<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-3%3Asdal039</id>
	<title>SE250:lab-3:sdal039 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-3%3Asdal039"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:sdal039&amp;action=history"/>
	<updated>2026-04-30T17:27:56Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE250:lab-3:sdal039&amp;diff=5761&amp;oldid=prev</id>
		<title>Mark: 5 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:sdal039&amp;diff=5761&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:27Z</updated>

		<summary type="html">&lt;p&gt;5 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Lab 3==&lt;br /&gt;
&lt;br /&gt;
Here is the code that I used to complete the tasks:&lt;br /&gt;
&lt;br /&gt;
 #include &amp;quot;arraylist.c&amp;quot;&lt;br /&gt;
 #include &amp;lt;time.h&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 int main() {&lt;br /&gt;
  clock_t t0;  &lt;br /&gt;
  ArrayList arr;&lt;br /&gt;
  int limit = 10000;&lt;br /&gt;
   int n;&lt;br /&gt;
 &lt;br /&gt;
  arraylist_init( &amp;amp;arr );&lt;br /&gt;
 &lt;br /&gt;
  t0 = clock();  &lt;br /&gt;
   for ( n = 0 ; n &amp;lt; limit ; n++ ) {&lt;br /&gt;
     arraylist_put(&amp;amp;arr, 1, 0 );&lt;br /&gt;
  }&lt;br /&gt;
  printf(&amp;quot;Time taken \t: %ld\n&amp;quot;, (clock() - t0));&lt;br /&gt;
 &lt;br /&gt;
  return 0;&lt;br /&gt;
 }&lt;br /&gt;
	&lt;br /&gt;
==Question 1==&lt;br /&gt;
&lt;br /&gt;
 Number of inserts	Time Taken	Memory Used (mb)&lt;br /&gt;
 	10^9		crash		440+&lt;br /&gt;
 	10^8		6313		360&lt;br /&gt;
 	10^7		640		&amp;lt; 10&lt;br /&gt;
 	10^6		62		&amp;lt; 10&lt;br /&gt;
 	10^5		0		&amp;lt; 10&lt;br /&gt;
&lt;br /&gt;
These results show that the amount memory used is minimal when the number of inserts is well below the crash threshold. &lt;br /&gt;
&lt;br /&gt;
==Question 2==&lt;br /&gt;
&lt;br /&gt;
 Growth Factor	Number of Inserts	Time Taken	Memory Used (mb)&lt;br /&gt;
 	 2		10^9		crash		440+&lt;br /&gt;
 	 		10^8		6313		360&lt;br /&gt;
 	 		10^7		640		&amp;lt; 10&lt;br /&gt;
 	 		10^6		62		&amp;lt; 10&lt;br /&gt;
 	 		10^5		0		&amp;lt; 10&lt;br /&gt;
 	 		&lt;br /&gt;
 	  4		10^8		crash		21+&lt;br /&gt;
 	 		10^7		500		&amp;lt; 10&lt;br /&gt;
 	 		10^6		47		&amp;lt; 10&lt;br /&gt;
 	 		10^5		0		&amp;lt; 10&lt;br /&gt;
 	 		&lt;br /&gt;
 	 16		10^8		crash		20+&lt;br /&gt;
 	 		10^7		452		10&lt;br /&gt;
 	 		10^6		46		10&lt;br /&gt;
 	 		10^5		0		10&lt;br /&gt;
 	 		&lt;br /&gt;
 	 64		10^8		crash		20+&lt;br /&gt;
 	 		10^7		crash		10+&lt;br /&gt;
 	 		10^6		46		10&lt;br /&gt;
 	 		10^5		0		10&lt;br /&gt;
 	 		&lt;br /&gt;
 	 1.125		10^8		12015		590&lt;br /&gt;
 	 		10^7		1109		70&lt;br /&gt;
 	 		10^6		109		10&lt;br /&gt;
 	 		10^5		0		10  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The results from this show that as the growth factor increases, the less inserts are needed to cause the program to run out of memory. If the number of inserts is not near this threshold however, it will take the same amount of time no matter the growth factor. &lt;br /&gt;
&lt;br /&gt;
As the growth factor approaches 1 the times taken increase rapidly, increasing by about 100%.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Question 3==&lt;br /&gt;
 Initial Size	Number of Inserts	Time Taken	Memory Used (mb)&lt;br /&gt;
 2^4		10^9			crash		440+&lt;br /&gt;
 		10^8			6313		360&lt;br /&gt;
 		10^7			640		&amp;lt; 10&lt;br /&gt;
 		10^6			62		&amp;lt; 10&lt;br /&gt;
 		10^5			0		&amp;lt; 10&lt;br /&gt;
 			&lt;br /&gt;
 2^8		10^8			6296		460&lt;br /&gt;
 		10^7			626		20&lt;br /&gt;
 		10^6			61		&amp;lt; 10&lt;br /&gt;
 		10^5			0		&amp;lt; 10&lt;br /&gt;
 			&lt;br /&gt;
 2^16		10^8			6093		410&lt;br /&gt;
 		10^7			609		10&lt;br /&gt;
 		10^6			46		&amp;lt; 10&lt;br /&gt;
 		10^5			0		10&lt;br /&gt;
 			&lt;br /&gt;
 2^20		10^8			6343		500&lt;br /&gt;
 		10^7			562		10&lt;br /&gt;
 		10^6			46		10&lt;br /&gt;
 		10^5			15		10&lt;br /&gt;
 			&lt;br /&gt;
 2^24		10^8			6265		410&lt;br /&gt;
 		10^7			499		10&lt;br /&gt;
 		10^6			46		&amp;lt; 10&lt;br /&gt;
 		10^5			15		&amp;lt; 10&lt;br /&gt;
&lt;br /&gt;
The results here show that the minimum array size has no noticeable effect on insertion time. This is probably because the time taken to fill up the first array of the initial size is insignificant when compared to the time taken to reallocate memory for each time the array fills up.&lt;br /&gt;
&lt;br /&gt;
==Question 4==&lt;br /&gt;
Normal&lt;br /&gt;
 Number of inserts	Time Taken&lt;br /&gt;
 10^9			crash&lt;br /&gt;
 10^8			6187&lt;br /&gt;
 10^7			562&lt;br /&gt;
 10^6			62&lt;br /&gt;
 10^5			15&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With ‘ensure_capacity’&lt;br /&gt;
 Number of inserts	Time Taken&lt;br /&gt;
 10^9			crash&lt;br /&gt;
 10^8			4860&lt;br /&gt;
 10^7			485&lt;br /&gt;
 10^6			47&lt;br /&gt;
 10^5			0&lt;br /&gt;
&lt;br /&gt;
Using ensure_capacity when you know the size of the array reduces the time taken by roughly 30%.&lt;br /&gt;
&lt;br /&gt;
==Question 5==&lt;br /&gt;
 Increment	Number of Inserts	Time Taken	Memory Used (mb)&lt;br /&gt;
 1000		10^9			Too long	&lt;br /&gt;
 		10^8			Too long	&lt;br /&gt;
 		10^7			21781		30&lt;br /&gt;
 		10^6			281	 	10&lt;br /&gt;
 		10^5			0		10&lt;br /&gt;
 			&lt;br /&gt;
 10000		10^8			Too long	&lt;br /&gt;
 		10^7			22234		600&lt;br /&gt;
 		10^6			265		10&lt;br /&gt;
 		10^5			0		&amp;lt; 10&lt;br /&gt;
 			&lt;br /&gt;
 1000000         10^8			44734		560&lt;br /&gt;
 		10^7			781		10&lt;br /&gt;
 		10^6			46		&amp;lt; 10&lt;br /&gt;
 		10^5			0		10&lt;br /&gt;
&lt;br /&gt;
Lesson learned: incremental growth factor takes a long time. Small inserts are still pretty quick, but the time taken increases exponentially as the number of inserts increases passed a specific point.&lt;br /&gt;
&lt;br /&gt;
Varying the amount to increase each time doesn&amp;#039;t seem to have too much effect on the time taken except for very large increments.&lt;br /&gt;
&lt;br /&gt;
==Question 6==&lt;br /&gt;
 Number of inserts	Time Taken	Memory Used (mb)&lt;br /&gt;
 10^6			Too long	90+&lt;br /&gt;
 10^5			4641		40&lt;br /&gt;
 10^4			46		40&lt;br /&gt;
 10^3			0		10&lt;br /&gt;
&lt;br /&gt;
arraylist_put takes a long time. This is because it has to shift the entire array contents along for every insert, as we are inserting into the first element (arr[0]).&lt;br /&gt;
&lt;br /&gt;
The magnitude of the number of inserts had to be lowered here as anything above 10^5 took too long.&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>