<?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%3Atlou006</id>
	<title>SE250:lab-6:tlou006 - 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%3Atlou006"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-6:tlou006&amp;action=history"/>
	<updated>2026-04-30T10:31:02Z</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:tlou006&amp;diff=7383&amp;oldid=prev</id>
		<title>Mark: 6 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-6:tlou006&amp;diff=7383&amp;oldid=prev"/>
		<updated>2008-11-03T05:20:10Z</updated>

		<summary type="html">&lt;p&gt;6 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Q1 ==&lt;br /&gt;
Using the code&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Pre&amp;gt;int size_of_tree,i;&lt;br /&gt;
	Node* node;&lt;br /&gt;
	&lt;br /&gt;
	for( size_of_tree = 0; size_of_tree &amp;lt; i ; size_of_tree++) {&lt;br /&gt;
		node = makeRandomTree(size_of_tree);&lt;br /&gt;
		printf(&amp;quot;height = %d for size = %d\n&amp;quot;, height( node ), size_of_tree);&lt;br /&gt;
	}&lt;br /&gt;
	show_tree( 0, node );&lt;br /&gt;
&amp;lt;/Pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Prints out a tree of 10nodes using random keys. Changing i will vary the size of the tree.&lt;br /&gt;
&lt;br /&gt;
My results showed positive but not linear relationship between size and height of the tree. Maybe its exponential or logarithmic?&lt;br /&gt;
&lt;br /&gt;
Ran out of time for the graph&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Q2 ==&lt;br /&gt;
Here are the functions for finding the minimum/maximum key values&lt;br /&gt;
&lt;br /&gt;
Using a simple tree model the minimum key value should be located in the leftmost bottom corner&lt;br /&gt;
while the maximum should be in the rightmost bottom corner&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Pre&amp;gt;Node* maximum( Node* node ) {&lt;br /&gt;
	while( node-&amp;gt;right != empty ){&lt;br /&gt;
		node = node-&amp;gt;right;&lt;br /&gt;
	}&lt;br /&gt;
	return node;&lt;br /&gt;
}&amp;lt;/Pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Pre&amp;gt;Node* minimum( Node* node ) {&lt;br /&gt;
	while( node-&amp;gt;left != empty ){&lt;br /&gt;
		node = node-&amp;gt;left;&lt;br /&gt;
	}&lt;br /&gt;
	return node;&lt;br /&gt;
}&amp;lt;/Pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I initially had some trouble working with the pointer input and struct types, but made it work with tutor help and trial/error&lt;br /&gt;
== Q3 ==&lt;br /&gt;
This function looks through the tree, branching left or right depending on the key value of the current node with the key we are looking for. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;Pre&amp;gt;Node* lookup( int key, Node* node ) {&lt;br /&gt;
	while( key != node-&amp;gt;key ){&lt;br /&gt;
&lt;br /&gt;
		if( key == node-&amp;gt;key ){&lt;br /&gt;
			return node;&lt;br /&gt;
		} else &lt;br /&gt;
&lt;br /&gt;
			if( ( node != empty ) &amp;amp;&amp;amp; ( key &amp;lt; node-&amp;gt;key ) ){&lt;br /&gt;
				node = node-&amp;gt;left;&lt;br /&gt;
			} else {&lt;br /&gt;
				node = node-&amp;gt;right;&lt;br /&gt;
			}&lt;br /&gt;
              return empty;&lt;br /&gt;
	} &lt;br /&gt;
}&amp;lt;/Pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will return an empty node if the key isnt found.&lt;br /&gt;
&lt;br /&gt;
At first I thought this method would not work and we had to use recursion to look through every single value in the tree, then someone pointed out that each node acted as a &amp;quot;sorter&amp;quot; for the next key; if the key was smaller it would be to the left of the current node, if bigger then it would be located to the right.&lt;br /&gt;
&lt;br /&gt;
== Q4 ==&lt;br /&gt;
Had a lot of trouble getting started with this question. First I thought we had to list the remaining sequence in Preorder, but I forgot how to implement recursion.&lt;br /&gt;
&lt;br /&gt;
After drawing a simple tree diagram by hand I managed to create a sequence of conditionals to check for the next value in Preorder&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Pre&amp;gt;Node* next_pre( Node* node ) {&lt;br /&gt;
	if( node-&amp;gt;parent == empty ){&lt;br /&gt;
&lt;br /&gt;
		if ( node-&amp;gt;left == empty ){&lt;br /&gt;
			return node-&amp;gt;right;&lt;br /&gt;
		} else {&lt;br /&gt;
			return node-&amp;gt;left;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
	} else&lt;br /&gt;
&lt;br /&gt;
		if( node-&amp;gt;parent-&amp;gt;right == empty ){&lt;br /&gt;
			return node-&amp;gt;parent;&lt;br /&gt;
		} else {&lt;br /&gt;
			return node-&amp;gt;parent-&amp;gt;right;&lt;br /&gt;
		}&lt;br /&gt;
     return empty;&lt;br /&gt;
}&amp;lt;/Pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Q5 ==&lt;br /&gt;
&lt;br /&gt;
report to follow&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>