<?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-7%3Avpup001</id>
	<title>SE250:lab-7:vpup001 - 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-7%3Avpup001"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-7:vpup001&amp;action=history"/>
	<updated>2026-05-02T18:37:11Z</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-7:vpup001&amp;diff=7943&amp;oldid=prev</id>
		<title>Mark: 22 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-7:vpup001&amp;diff=7943&amp;oldid=prev"/>
		<updated>2008-11-03T05:20:22Z</updated>

		<summary type="html">&lt;p&gt;22 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This lab is about balancing binary search trees.&lt;br /&gt;
The code is run by using GNU compiler.&lt;br /&gt;
==Task 1==&lt;br /&gt;
I have inserted the numbers, &amp;quot;4,5,6,7,3,2&amp;quot; and the tree looks like this...&lt;br /&gt;
&lt;br /&gt;
      2&lt;br /&gt;
    3&lt;br /&gt;
  4 (*)&lt;br /&gt;
    5&lt;br /&gt;
      6&lt;br /&gt;
        7&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;(*)&amp;#039; next to the element &amp;#039;4&amp;#039; means it is the node.&lt;br /&gt;
&lt;br /&gt;
When we use the command &amp;#039;left&amp;#039; the node moves one step down to left child (left child is selected).&lt;br /&gt;
&lt;br /&gt;
      2&lt;br /&gt;
    3 (*)&lt;br /&gt;
  4 &lt;br /&gt;
    5&lt;br /&gt;
      6&lt;br /&gt;
        7&lt;br /&gt;
&lt;br /&gt;
When we use the command &amp;#039;right&amp;#039; the node moves one step down to right child (right child is selected).&lt;br /&gt;
&lt;br /&gt;
      2&lt;br /&gt;
    3&lt;br /&gt;
  4 &lt;br /&gt;
    5 (*)&lt;br /&gt;
      6&lt;br /&gt;
        7&lt;br /&gt;
&lt;br /&gt;
If there is no right or left child to that particular node then nothing is selected.&lt;br /&gt;
&lt;br /&gt;
When we use the command &amp;#039;root&amp;#039;, the root of the tree should be selected (in this case 4).&lt;br /&gt;
&lt;br /&gt;
      2&lt;br /&gt;
    3&lt;br /&gt;
  4 (*)&lt;br /&gt;
    5&lt;br /&gt;
      6&lt;br /&gt;
        7&lt;br /&gt;
&lt;br /&gt;
When we use the command &amp;#039;parent&amp;#039;, the parent should be selected. For example if (*) is next to &amp;#039;6&amp;#039; and we used parent command, it should be displayed next to &amp;#039;5&amp;#039; (since 5 is the parent of 6)&lt;br /&gt;
&lt;br /&gt;
      2&lt;br /&gt;
    3&lt;br /&gt;
  4 &lt;br /&gt;
    5 (*)&lt;br /&gt;
      6&lt;br /&gt;
        7&lt;br /&gt;
&lt;br /&gt;
*The command &amp;#039;delete&amp;#039; is supposed to delete the element &amp;#039;(*)&amp;#039; is pointing to but its deleting the root!!!!&lt;br /&gt;
*The parent is not working properly. If the (*) is pointing to 7 and we used parent command it is pointing to 5 when it is suppose to point to 6 (since 6 is the parent of 7).&lt;br /&gt;
&lt;br /&gt;
==Task 2==&lt;br /&gt;
&lt;br /&gt;
Inserting elements a-g such that the tree is perfectly balanced.&lt;br /&gt;
&lt;br /&gt;
The order of insertion was... &amp;quot;d,b,c,a,f,g,e&amp;quot;&lt;br /&gt;
      a&lt;br /&gt;
    b&lt;br /&gt;
      c &lt;br /&gt;
  d (*)&lt;br /&gt;
      e&lt;br /&gt;
    f&lt;br /&gt;
      g&lt;br /&gt;
&lt;br /&gt;
There are other orders of inserting elements which result in a perfectly balanced tree but the root should always be &amp;#039;d&amp;#039; and the children of &amp;#039;d&amp;#039; should always be &amp;#039;b&amp;#039; and &amp;#039;f&amp;#039;. We can insert the other elements in any order.&lt;br /&gt;
&lt;br /&gt;
The other orders of insertion are...&lt;br /&gt;
&lt;br /&gt;
&amp;quot;d,b,a,c,f,e,g&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;d,f,b,g,e,c,a&amp;quot; and so on...&lt;br /&gt;
&lt;br /&gt;
*The order of insertion differs but the order is always the same which is &amp;quot;Tree[a,b,c,*d*,e,f,g]&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==Task 3==&lt;br /&gt;
&lt;br /&gt;
The perfectly balanced tree...&lt;br /&gt;
&lt;br /&gt;
      a&lt;br /&gt;
    b&lt;br /&gt;
      c &lt;br /&gt;
  d (*)&lt;br /&gt;
      e&lt;br /&gt;
    f&lt;br /&gt;
      g&lt;br /&gt;
&lt;br /&gt;
The order of the tree is printed by using &amp;#039;print&amp;#039; command.&lt;br /&gt;
&lt;br /&gt;
Tree[a,b,c,*d*,e,f,g]&lt;br /&gt;
&lt;br /&gt;
The tree is skewed by using &amp;#039;skew&amp;#039; and it looks like this...&lt;br /&gt;
&lt;br /&gt;
 a (*)&lt;br /&gt;
   b&lt;br /&gt;
     c&lt;br /&gt;
       d&lt;br /&gt;
         e&lt;br /&gt;
           f&lt;br /&gt;
             g&lt;br /&gt;
&lt;br /&gt;
The order...&lt;br /&gt;
&lt;br /&gt;
Tree[*a*,b,c,d,e,f,g]&lt;br /&gt;
&lt;br /&gt;
When a left rotation is performed on the root...&lt;br /&gt;
&lt;br /&gt;
      a &lt;br /&gt;
   b (*)&lt;br /&gt;
     c&lt;br /&gt;
       d&lt;br /&gt;
         e&lt;br /&gt;
           f&lt;br /&gt;
             g&lt;br /&gt;
&lt;br /&gt;
The order is...&lt;br /&gt;
&lt;br /&gt;
Tree[*a*,b,c,d,e,f,g]&lt;br /&gt;
*The order of the tree is the same before and after the rotation. It is the structure of the tree that changes (root changes).&lt;br /&gt;
&lt;br /&gt;
==Task 4==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;rotate left&amp;quot; rotates the selected node to left and &amp;quot;rotate right&amp;quot; rotates the selected node to right.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; rl&lt;br /&gt;
  a (*)&lt;br /&gt;
b&lt;br /&gt;
  c&lt;br /&gt;
    d&lt;br /&gt;
      e&lt;br /&gt;
        f&lt;br /&gt;
          g&lt;br /&gt;
&amp;gt; root&lt;br /&gt;
  a&lt;br /&gt;
b (*)&lt;br /&gt;
  c&lt;br /&gt;
    d&lt;br /&gt;
      e&lt;br /&gt;
        f&lt;br /&gt;
          g&lt;br /&gt;
&lt;br /&gt;
&amp;gt; rl&lt;br /&gt;
    a&lt;br /&gt;
  b (*)&lt;br /&gt;
c&lt;br /&gt;
  d&lt;br /&gt;
    e&lt;br /&gt;
      f&lt;br /&gt;
        g&lt;br /&gt;
&lt;br /&gt;
&amp;gt; parent&lt;br /&gt;
    a&lt;br /&gt;
  b&lt;br /&gt;
c (*)&lt;br /&gt;
  d&lt;br /&gt;
    e&lt;br /&gt;
      f&lt;br /&gt;
        g&lt;br /&gt;
&lt;br /&gt;
&amp;gt; rr&lt;br /&gt;
  a&lt;br /&gt;
b&lt;br /&gt;
  c (*)&lt;br /&gt;
    d&lt;br /&gt;
      e&lt;br /&gt;
        f&lt;br /&gt;
          g&lt;br /&gt;
&lt;br /&gt;
&amp;gt; rl&lt;br /&gt;
  a&lt;br /&gt;
b&lt;br /&gt;
    c (*)&lt;br /&gt;
  d&lt;br /&gt;
    e&lt;br /&gt;
      f&lt;br /&gt;
        g&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*In the last tree, I have used &amp;#039;rl&amp;#039; when &amp;#039;c&amp;#039; was selected so the tree rotates from c (the whole tree doesn&amp;#039;t rotate)!!&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>