SE250:lab-7:rbha033

From Marks Wiki
Jump to navigation Jump to search

Lab 7

Task 1

Task 1 was fun easy as hell... but I'm glad. Finally something I can handle HEHEHEHE! just jokes. I've used every command and feel proficient in the program. ;)

Task 2

Ok so now I have to insert a-g in such an order that the tree is perfectly balanced. Here's the characters: a b c d e f g Here's how I chose to insert them:

a b c D e f g
a b c D e F
a B c D e F g
A B c D e F g
A B C D e F g
A B C D E F g
A B C D E F G

And this is the result:

> DISPLAY
    a
  b
    c
d (*)
    e
  f
    g

Basically my strategy was to choose the median value each time and split the array of values to be inserted about the median. The first time I chose D which was right in the middle a b c D e f g. This gave me 2 groups: ABC & EFG. Then I repeated this method with each group.

Just to see how the program would BALANCE these letters:

> SKEW
a (*)
  b
    c
      d
        e
          f
            g

> BALANCE
    a
  b
    c
d (*)
    e
  f
    g

Since the number of elements is odd, no matter in which order the elements are inserted using the MEDIAN method, they'll always give the same result for a perfectly balanced tree.

Task 3

After re-performing the SKEW:

> SKEW
a (*)
  b
    c
      d
        e
          f
            g

> r l
  a (*)
b
  c
    d
      e
        f
          g

> print
Tree[*a*,b,c,d,e,f,g]

Hence, the elements are still in the same order, but now the root is b.

          b
        c   a
      d
    e
  f
g