<?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%3Aaomr001</id>
	<title>SE250:lab-3:aomr001 - 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%3Aaomr001"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:aomr001&amp;action=history"/>
	<updated>2026-04-29T01:17:15Z</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:aomr001&amp;diff=5448&amp;oldid=prev</id>
		<title>Mark: 1 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-3:aomr001&amp;diff=5448&amp;oldid=prev"/>
		<updated>2008-11-03T05:19:17Z</updated>

		<summary type="html">&lt;p&gt;1 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== task1 ==&lt;br /&gt;
code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int main(){&lt;br /&gt;
  ArrayList mylist;&lt;br /&gt;
  int i,x;&lt;br /&gt;
  arraylist_init(&amp;amp;mylist);&lt;br /&gt;
  x= clock();&lt;br /&gt;
  for( i=0; i &amp;lt; 1000000; i++){&lt;br /&gt;
    arraylist_push(&amp;amp;mylist,4);&lt;br /&gt;
   &lt;br /&gt;
  }&lt;br /&gt;
  x = clock() - x;&lt;br /&gt;
&lt;br /&gt;
  printf(&amp;quot;the operation took %d ms to push 1 million elements into the array.&amp;quot;,x);&lt;br /&gt;
&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
the operation took 46 ms to push 1 million elements into the array&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
i changed the number i was adding to 400:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
the operation took 47 ms to push 1 million elements into the array.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== task2 ==&lt;br /&gt;
i changed the growth factor inside the push function to :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(int)(alist-&amp;gt;capacity *90000000 )&lt;br /&gt;
&lt;br /&gt;
(int)(alist-&amp;gt;capacity * 4.0)&lt;br /&gt;
(int)(alist-&amp;gt;capacity * 3.0)&lt;br /&gt;
(int)(alist-&amp;gt;capacity * 1.8)&lt;br /&gt;
(int)(alist-&amp;gt;capacity * 1.5)&lt;br /&gt;
(int)(alist-&amp;gt;capacity * 1.2)&lt;br /&gt;
(int)(alist-&amp;gt;capacity * 1.1)&lt;br /&gt;
(int)(alist-&amp;gt;capacity * 1.05)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ERROR: assertion &amp;quot;alist-&amp;gt;arr != (element_t*)0&amp;quot; failed: file &amp;quot;arraylist-2.c&amp;quot;, line 39 /usr/bin/bash: line 1:  3024 Hangup                  ./arraylist-2.exe&lt;br /&gt;
&lt;br /&gt;
the operation took 46 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 47 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 46 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 61 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 93 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 156 ms to push 1 million elements into the array.&lt;br /&gt;
ERROR: /usr/bin/bash: line 1:  4960 Segmentation fault      (core dumped) ./arraylist-2.exe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment:&lt;br /&gt;
It&amp;#039;s clear that as the factor is decreased the time taken is increased. This is mainly because of the way reallocations&lt;br /&gt;
work, if all of the space availabe is used a new BIGGER array is created and all of the values are copied into it, new data will&lt;br /&gt;
be copied until there is no enough space for new data to be copied .. another array is created. &lt;br /&gt;
The smaller the array created the more we are going to need to create arry, move data , which obviously takes more time.  &lt;br /&gt;
&lt;br /&gt;
Very large factors would exhaust all of the memory available and cause the program to crash. &lt;br /&gt;
Very small factors would mean that there is no enough space to add new element which also crashed the program.&lt;br /&gt;
&lt;br /&gt;
== task3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define ARRAYLIST_MIN_ALLOC 10000000&lt;br /&gt;
#define ARRAYLIST_MIN_ALLOC 1000000&lt;br /&gt;
#define ARRAYLIST_MIN_ALLOC 1000&lt;br /&gt;
#define ARRAYLIST_MIN_ALLOC 90&lt;br /&gt;
#define ARRAYLIST_MIN_ALLOC 60&lt;br /&gt;
#define ARRAYLIST_MIN_ALLOC 9&lt;br /&gt;
#define ARRAYLIST_MIN_ALLOC 2&lt;br /&gt;
#define ARRAYLIST_MIN_ALLOC 1&lt;br /&gt;
#define ARRAYLIST_MIN_ALLOC 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
the operation took 47 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 46 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 47 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 46 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 62 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 62 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 78 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 63 ms to push 1 million elements into the array.&lt;br /&gt;
/usr/bin/bash: line 1:  4860 Segmentation fault      (core dumped) ./arraylist-2.exe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
comment: &lt;br /&gt;
Starting with a small array would mean that it will take shorter time until the it&amp;#039;s forced to created a bigger array,&lt;br /&gt;
while starting with a large array would save time .. as the array doesn&amp;#039;t have to go through the proccess&lt;br /&gt;
of creating and move elements to a new array.&lt;br /&gt;
&lt;br /&gt;
== task 4 ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int main(){&lt;br /&gt;
  ArrayList mylist;&lt;br /&gt;
  int i,x;&lt;br /&gt;
  arraylist_init(&amp;amp;mylist);&lt;br /&gt;
   ensure_capacity(&amp;amp;mylist,1000000);&lt;br /&gt;
  x= clock();&lt;br /&gt;
  for( i=0; i &amp;lt; 1000000; i++){&lt;br /&gt;
    arraylist_push(&amp;amp;mylist,4);&lt;br /&gt;
     }&lt;br /&gt;
  x = clock() - x;&lt;br /&gt;
&lt;br /&gt;
  printf(&amp;quot;the operation took %d ms to push 1 million elements into the array.&amp;quot;,x);&lt;br /&gt;
&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
the operation took 31 ms to push 1 million elements into the array.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
comment:&lt;br /&gt;
the program doesnt have to creat a new bigger array every time .. &lt;br /&gt;
as it already knows how much it needs and was created with the exact number of elements as it needs. &lt;br /&gt;
&lt;br /&gt;
== task5 ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(int)(alist-&amp;gt;capacity + 10000)&lt;br /&gt;
(int)(alist-&amp;gt;capacity + 1000)&lt;br /&gt;
(int)(alist-&amp;gt;capacity + 300)&lt;br /&gt;
(int)(alist-&amp;gt;capacity + 100)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
the operation took 47 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 46 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 46 ms to push 1 million elements into the array.&lt;br /&gt;
the operation took 46 ms to push 1 million elements into the array.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== task6 == &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int main(){&lt;br /&gt;
  ArrayList mylist;&lt;br /&gt;
  int i,x;&lt;br /&gt;
  arraylist_init(&amp;amp;mylist);&lt;br /&gt;
  x= clock();&lt;br /&gt;
  for( i=0; i &amp;lt; 10000; i++){&lt;br /&gt;
    arraylist_put(&amp;amp;mylist,4,0);&lt;br /&gt;
   &lt;br /&gt;
  }&lt;br /&gt;
  x = clock() - x;&lt;br /&gt;
&lt;br /&gt;
  printf(&amp;quot;the operation took %d ms to push 1 million elements into the array.&amp;quot;,x);&lt;br /&gt;
&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
the operation took 47 ms to push 1 million elements into the array.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>