SE250:lab-7:dcho040

From Marks Wiki
Jump to navigation Jump to search

discussion

it was easy lab and most stuff we already learn

task1

left: move to left node right: move to right node root: move to root

task2

    a
  b
    c
d 
    e
  f
    g
This is only one way to balance in this case

task3

rotate right from task2
  a
b
    c
  d (*)
      e
    f
      g

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

tree is rotated but print shows the same results
because print show preorder which shows from small to big

task4

right rotation : right node goes to parent of the node selected

                and that parent's left node goes to the right position of the node selected

left rotation : opposite

task5

repeat 'root' and 'rotate left'

task6

rotate left root rotate left root rotate left rotate right root right rotate left

task7

   a
 b
   c

d

   e
 f
   g (*)
     h
       i

rotate left

   a
 b
   c

d

   e
 f
     g (*)
   h
     i

done

task8

I think it's possible it's balanced before insert or delete and shold check rotating the node from leaf to roof because before reach the leaf we don't know we need rotating or not