<?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%3Allay008</id>
	<title>SE250:lab-7:llay008 - 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%3Allay008"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-7:llay008&amp;action=history"/>
	<updated>2026-06-08T20:54:48Z</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:llay008&amp;diff=7680&amp;oldid=prev</id>
		<title>Mark: 19 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-7:llay008&amp;diff=7680&amp;oldid=prev"/>
		<updated>2008-11-03T05:20:16Z</updated>

		<summary type="html">&lt;p&gt;19 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Getting Started==&lt;br /&gt;
I arrived early to start this lab, but all in vain because it wouldn&amp;#039;t compile.  I tried emacs numerous times and even tried Visual Studio, but all I got were errors.  In the end I used the command window.  I was quite rusty on this - I have not used this since last year but was fine once I got going.&lt;br /&gt;
&lt;br /&gt;
The first thing that struct me was that the tree was rotated on its side... and that the directions were &amp;#039;&amp;#039;the wrong way round&amp;#039;&amp;#039;.  When I rotated the screen left was right and vice versa, so I just thought of it as &amp;#039;&amp;#039;up is left&amp;#039;&amp;#039; and &amp;#039;&amp;#039;down is right&amp;#039;&amp;#039;.  It took some playing around to see how it all fit together.  &lt;br /&gt;
&lt;br /&gt;
One error(?) that I noticed was unless the current node was one branch away from the root, the &amp;#039;&amp;#039;&amp;#039;parent&amp;#039;&amp;#039;&amp;#039; command, instead of moving to the current node&amp;#039;s parent, it moved to its parent&amp;#039;s parent.&lt;br /&gt;
&lt;br /&gt;
==Creating a Perfectly Balanced Tree==&lt;br /&gt;
Since there are only 7 elements, it is easy to see how to do this.  We did a similar example in class.  It was with numbers, not letters, but the principle was the same.  Obviously there are a few variations with the same idea that will also give you a perfectly balanced tree.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Order:&lt;br /&gt;
d   b a c   f e g&lt;br /&gt;
d   f e g   b a c &lt;br /&gt;
d   b   f   a c  e g&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
etc...  Obviously, it is also possible to create the tree by creating a skewed tree and then balance it by rotating, but this I believe it the next task...&lt;br /&gt;
&lt;br /&gt;
==Skewing the Tree==&lt;br /&gt;
Here is my tree from the last task.&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using the &amp;#039;&amp;#039;&amp;#039;print&amp;#039;&amp;#039;&amp;#039; command I get the following output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Tree[a,b,c,*d*,e,f,g]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
What happens when I try to perform a left rotation on the root?  I get this output:&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you can see the tree has rotated so that &amp;#039;&amp;#039;f&amp;#039;&amp;#039; is now the root.&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;print&amp;#039;&amp;#039;&amp;#039; command gives:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Tree[a,b,c,*d*,e,f,g]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As was expected, the order of the elements has not changed.&lt;br /&gt;
&lt;br /&gt;
==Right Skew Tree==&lt;br /&gt;
==Getting Started==&lt;br /&gt;
I arrived early to start this lab, but all in vain because it wouldn&amp;#039;t compile.  I tried emacs numerous times and even tried Visual Studio, but all I got were errors.  In the end I used the command window.  I was quite rusty on this - I have not used this since last year but was fine once I got going.&lt;br /&gt;
&lt;br /&gt;
The first thing that struct me was that the tree was rotated on its side... and that the directions were &amp;#039;&amp;#039;the wrong way round&amp;#039;&amp;#039;.  When I rotated the screen left was right and vice versa, so I just thought of it as &amp;#039;&amp;#039;up is left&amp;#039;&amp;#039; and &amp;#039;&amp;#039;down is right&amp;#039;&amp;#039;.  It took some playing around to see how it all fit together.  &lt;br /&gt;
&lt;br /&gt;
One error(?) that I noticed was unless the current node was one branch away from the root, the &amp;#039;&amp;#039;&amp;#039;parent&amp;#039;&amp;#039;&amp;#039; command, instead of moving to the current node&amp;#039;s parent, it moved to its parent&amp;#039;s parent.&lt;br /&gt;
&lt;br /&gt;
==Creating a Perfectly Balanced Tree==&lt;br /&gt;
Since there are only 7 elements, it is easy to see how to do this.  We did a similar example in class.  It was with numbers, not letters, but the principle was the same.  Obviously there are a few variations with the same idea that will also give you a perfectly balanced tree.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Order:&lt;br /&gt;
d   b a c   f e g&lt;br /&gt;
d   f e g   b a c &lt;br /&gt;
d   b   f   a c  e g&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
etc...  Obviously, it is also possible to create the tree by creating a skewed tree and then balance it by rotating, but this I believe it the next task...&lt;br /&gt;
&lt;br /&gt;
==Skewing the Tree==&lt;br /&gt;
Here is my tree from the last task.&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Using the &amp;#039;&amp;#039;&amp;#039;print&amp;#039;&amp;#039;&amp;#039; command I get the following output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Tree[a,b,c,*d*,e,f,g]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
What happens when I try to perform a left rotation on the root?  I get this output:&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you can see the tree has rotated so that &amp;#039;&amp;#039;f&amp;#039;&amp;#039; is now the root.&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;print&amp;#039;&amp;#039;&amp;#039; command gives:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Tree[a,b,c,*d*,e,f,g]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As was expected, the order of the elements has not changed.&lt;br /&gt;
&lt;br /&gt;
==Right Skew Tree to Left Skew Tree==&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To do this task, use &amp;#039;&amp;#039;&amp;#039;rl&amp;#039;&amp;#039;&amp;#039; to rotate the tree left.  Then use &amp;#039;&amp;#039;&amp;#039;parent&amp;#039;&amp;#039;&amp;#039; so that the current node is now the root.&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Repeat this process until your tree is left skewed!&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Right Skew Tree to Balanced Tree==&lt;br /&gt;
Start&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Rotate Left and Change Current Node to Root (&amp;#039;&amp;#039;&amp;#039;rl&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;parent&amp;#039;&amp;#039;&amp;#039;) * 2&lt;br /&gt;
&lt;br /&gt;
Rotate Left&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then Rotate Right&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Parent&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Right&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Rotate Left&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finished!!&lt;br /&gt;
&amp;lt;pre&amp;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;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Add Two Elements and Then Balance Tree==&lt;br /&gt;
To start, insert the elements &amp;#039;&amp;#039;h&amp;#039;&amp;#039; and &amp;#039;&amp;#039;i&amp;#039;&amp;#039;.&lt;br /&gt;
&amp;lt;pre&amp;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;
      h&lt;br /&gt;
        i&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Move Right.&lt;br /&gt;
&lt;br /&gt;
Rotate Right.&lt;br /&gt;
&amp;lt;pre&amp;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;
        h&lt;br /&gt;
          i&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Parent&lt;br /&gt;
&lt;br /&gt;
Rotate Left&lt;br /&gt;
&amp;lt;pre&amp;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;
      h&lt;br /&gt;
        i&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Left&lt;br /&gt;
&lt;br /&gt;
Rotate Left&lt;br /&gt;
&amp;lt;pre&amp;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;
      h  &lt;br /&gt;
        i &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Parent&lt;br /&gt;
&lt;br /&gt;
Rotate Right&lt;br /&gt;
&amp;lt;pre&amp;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;
      h&lt;br /&gt;
        i&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Parent&lt;br /&gt;
&lt;br /&gt;
Right&lt;br /&gt;
&lt;br /&gt;
Rotate Left&lt;br /&gt;
&lt;br /&gt;
Finished!!!&lt;br /&gt;
&amp;lt;pre&amp;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;
    h&lt;br /&gt;
      i&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>