SE250:lab-7:srag014

From Marks Wiki
Jump to navigation Jump to search

Lab 7

This lab is all about balancing binary search trees. This lab took me a while to "set up" and get everything going as the code wouldnt work in Visual Studio. Visual Studio is pretty much all I use for this paper and setting it up on MinGw took a while and it was sort of confusin...but I got there in the end with some help.Think Im going to redo the lab without any help just so i get familiar without using visual studio.


Task 1

The first task was just to familiarize/play around with the commands. I felt they were easy! and pretty straightforward. The Help option came in handy on this one!

Task 2

The second task was to create a perfectly balanced tree by inserting the seven elements a–g in such an order that the resulting tree is perfectly balanced.

    a
  b
    c
d (*)
    e
  f
    g

Do any other insertion orders also result in a perfectly balanced tree? No, because for the tree to to be perfectly balanced the median (which is d) has to be in the middle and the upper quartile (letters above median) and lower quartile (letters below median) should be on either side.

Task 3

The third task was to skew the tree.

a (*)
  b
    c
      d
        e
          f
            g

Now we had to perform a left rotation on the root.

  a (*)
b
  c
    d
      e
        f
          g

This task was a bit tricky as i was a bit confused on what to do, i ended up making the whole tree left skewed but i got some help from my neighbor.

Task 4

The fourth task was basically just getting some practice for rotating the tree in both directions, just having a play around.

Task 5

Task five involved making a reight skew tree to a left skew one. This task was ok as i kind of did in the previous one.Basically just involved going through every element in the tree and rotating left.(parent and rotating commands used)

            a
          b
        c
      d
    e
  f
g (*)

Task 6

Task 6 involved reshaping a right skew tree into a balanced (minimum height) tree.