<?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-6%3Arwan064</id>
	<title>SE250:lab-6:rwan064 - 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-6%3Arwan064"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-6:rwan064&amp;action=history"/>
	<updated>2026-04-29T01:14:25Z</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-6:rwan064&amp;diff=7279&amp;oldid=prev</id>
		<title>Mark: 30 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-6:rwan064&amp;diff=7279&amp;oldid=prev"/>
		<updated>2008-11-03T05:20:08Z</updated>

		<summary type="html">&lt;p&gt;30 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
== Task 1 ==&lt;br /&gt;
&lt;br /&gt;
=== Plan ===&lt;br /&gt;
&lt;br /&gt;
* Plan&lt;br /&gt;
** Measure the expected height of a binary search tree.&lt;br /&gt;
** Plot the height for a range of tree sizes.&lt;br /&gt;
** Propose a relationship between the size and height for such trees.&lt;br /&gt;
&lt;br /&gt;
* Variables:&lt;br /&gt;
** height&lt;br /&gt;
** tree size (number of elements)&lt;br /&gt;
** y-axis: height&lt;br /&gt;
** x-axis: tree size (0-1000)&lt;br /&gt;
&lt;br /&gt;
Pseudo code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int height;&lt;br /&gt;
for i = 0 to 1000&lt;br /&gt;
  Tree = makeRandomTree( i );&lt;br /&gt;
  height = height(Tree);&lt;br /&gt;
  Print ( height );&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the given function &amp;#039;&amp;#039;&amp;#039;makeRandomTree( int )&amp;#039;&amp;#039;&amp;#039; I made random trees of varying sizes and calculated the height of each of these trees and printed them to the screen. When I wanted to make the graph I just piped the output to a file using Cygwin.&lt;br /&gt;
&lt;br /&gt;
Command to run program:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
make &amp;amp;&amp;amp; ./lab-6.exe &amp;gt;&amp;gt; output.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code used to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;image src=&amp;quot;http://studwww.cs.auckland.ac.nz/~rwan064/lab6/task1main.PNG&amp;quot; width=&amp;quot;347&amp;quot; height=&amp;quot;253&amp;quot; alt=&amp;quot;task1&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[SE250:lab-6:rwan064:Makefile| The Makefile]]&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
Using the values in [[SE250:lab-6:rwan064:output.txt | output.txt]] I made a graph using Excel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;image src=&amp;quot;http://studwww.cs.auckland.ac.nz/~rwan064/lab6/task1.png&amp;quot; width=&amp;quot;609&amp;quot; height=&amp;quot;358&amp;quot; alt=&amp;quot;task1&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a graph of log(x) vs. x:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;image src=&amp;quot;http://studwww.cs.auckland.ac.nz/~rwan064/lab6/xlogx.png&amp;quot; width=&amp;quot;552&amp;quot; height=&amp;quot;340&amp;quot; alt=&amp;quot;task1&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Comparing the two graphs it seems like it&amp;#039;s a logarithmic relationship. Hence:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Height of Tree = Log( Tree size )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Task 2 ==&lt;br /&gt;
&lt;br /&gt;
These two functions were quite easy to implement since this is a Binary Search Tree. Therefore the minimum is the left-most Node. And the maximum is the right-most Node. Hence for the minimum I just need to keep getting the left Node until I reach the empty node. Then return the last Node before the empty Node. The same goes for the maximum function, except in that case I would go on the right side.&lt;br /&gt;
&lt;br /&gt;
The code for the &amp;#039;&amp;#039;&amp;#039;minimum&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;maximum&amp;#039;&amp;#039;&amp;#039; functions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;image src=&amp;quot;http://studwww.cs.auckland.ac.nz/~rwan064/lab6/task2.PNG&amp;quot; width=&amp;quot;336&amp;quot; height=&amp;quot;507&amp;quot; alt=&amp;quot;min-max&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Task 3 ==&lt;br /&gt;
&lt;br /&gt;
The lookup function was also quite simple. Starting at the root, check if the key at the root is what we want. If not, check if the key is smaller or greater than the key of the root. If it&amp;#039;s smaller, go to the left Node. Otherwise, go to the right. If an empty Node is reached, it means the key cannot be found in this tree. So return the empty Node in that case.&lt;br /&gt;
&lt;br /&gt;
The code for the &amp;#039;&amp;#039;&amp;#039;lookup&amp;#039;&amp;#039;&amp;#039; function looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;image src=&amp;quot;http://studwww.cs.auckland.ac.nz/~rwan064/lab6/lookup.PNG&amp;quot; width=&amp;quot;388&amp;quot; height=&amp;quot;379&amp;quot; alt=&amp;quot;lookup&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Task 4 ==&lt;br /&gt;
== Task 5 ==&lt;br /&gt;
== Task 6 ==&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>