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

		<summary type="html">&lt;p&gt;18 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Task 1==&lt;br /&gt;
Familiarizing with the given codes were tough. However the commands and introduction given were rather simple, however I find it irritating how the tree are displayed in the cmd prompt, it was REALLY irritating to navigate through, even for a short tree.... as the tree aren&amp;#039;t displayed properly and you would have to first navigate through them to figure out which values went where...&lt;br /&gt;
&lt;br /&gt;
*Note: the &amp;quot;parent&amp;quot; command seen to not work..., jumping 2 nodes above instead of 1.&lt;br /&gt;
*Note: actually, after going through Task 2, the tree&amp;#039;s appearance seen to become clear, except the orientation of the nodes seen to be off, right = down, left = up. Whereas if right = up, left = down, makes more sense as tilting your head on the side gives you the tree.&lt;br /&gt;
&lt;br /&gt;
==Task 2==&lt;br /&gt;
*Inserting the char in the given order &amp;quot;d b f a c e g&amp;quot; gives a perfectly balanced tree:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
         d&lt;br /&gt;
      __/ \__&lt;br /&gt;
     b       f&lt;br /&gt;
    / \     / \&lt;br /&gt;
   a   c   e   g&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Inserting the char in an order such that:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;d&amp;quot; is inserted first&lt;br /&gt;
&amp;quot;b&amp;quot; and &amp;quot;f&amp;quot; are inserted next&lt;br /&gt;
&amp;quot;a&amp;quot; &amp;quot;c&amp;quot; &amp;quot;e&amp;quot; &amp;quot;g&amp;quot; are inserted last&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
gives a perfectly balanced tree, ie. inserting the tree in &amp;quot;level order&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
*Any other order simply will not work due to the code not manipulating the tree and comparing the values to be inserted with the parent of the base nodes.&lt;br /&gt;
&lt;br /&gt;
==Task 3==&lt;br /&gt;
*Skewing the tree gives the expected shape of a linked list:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
a&lt;br /&gt;
 \&lt;br /&gt;
  b&lt;br /&gt;
   \&lt;br /&gt;
    c&lt;br /&gt;
     \&lt;br /&gt;
      d&lt;br /&gt;
       \&lt;br /&gt;
        e&lt;br /&gt;
         \&lt;br /&gt;
          f&lt;br /&gt;
           \&lt;br /&gt;
            g&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Rotating left on Node a, should give:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  b&lt;br /&gt;
 / \&lt;br /&gt;
a   c&lt;br /&gt;
     \&lt;br /&gt;
      d&lt;br /&gt;
       \&lt;br /&gt;
        e&lt;br /&gt;
         \&lt;br /&gt;
          f&lt;br /&gt;
           \&lt;br /&gt;
            g&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
which was right when the tree is printed:&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;
==Task 4==&lt;br /&gt;
Again, this was all fun and game, rotating each nodes left and right... blah blah blah...&lt;br /&gt;
&lt;br /&gt;
==Task 5==&lt;br /&gt;
This was pretty random... the following commands were repeated until the last nodes is flipped into position.&lt;br /&gt;
*rl    //rotating the root node left&lt;br /&gt;
*root  //moves the targeted nodes to the new root node&lt;br /&gt;
*rl&lt;br /&gt;
*root&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
Result should look like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
             g&lt;br /&gt;
            /&lt;br /&gt;
           f&lt;br /&gt;
          /&lt;br /&gt;
         e&lt;br /&gt;
        /&lt;br /&gt;
       d&lt;br /&gt;
      /&lt;br /&gt;
     c&lt;br /&gt;
    /&lt;br /&gt;
   b&lt;br /&gt;
  /&lt;br /&gt;
 a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Result printed in cygwin:&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;
==Task 6==&lt;br /&gt;
In order to achieve a perfectly balanced tree from a right skewed tree, the following were done.&lt;br /&gt;
&lt;br /&gt;
1)Point the node to the root.&lt;br /&gt;
2)Rotate left.&lt;br /&gt;
3)Repeat 1) and 2) until the root node is d.&lt;br /&gt;
4)Place the node to c (the left children of the root node d).&lt;br /&gt;
5)Rotate right on root c, putting c under b and in the same level as a.&lt;br /&gt;
6)Place the node to e (the right children of the root node d).&lt;br /&gt;
7)Rotate left on root e, putting e under f and in the same level as g.&lt;br /&gt;
&lt;br /&gt;
==Task 7==&lt;br /&gt;
Starting with the balanced tree, adding h and i.&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;
Reshaping the tree in such a way that e is the root node with left children and right children at it&amp;#039;s longest length(ie back tracking task 6).&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;
Then perform a similar procedure as task 6, to achieve a balanced 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;
    h&lt;br /&gt;
      i&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Alternatively, a &amp;quot;balanced&amp;quot; tree with the same length could b obtained simply by rotating left on node g in the first diagram to produce the following.&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;
&lt;br /&gt;
==Task 8==&lt;br /&gt;
Yes, it is possible, because when removing or adding elements into the tree, only the subtree containing the added/removed element are altered. Therefore it can be balanced simply by transversing along the subtree that is affected.&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>