SE250:lab-7:sbas046

From Marks Wiki
Revision as of 05:20, 3 November 2008 by Mark (Sọ̀rọ̀ | contribs) (6 revision(s))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Inserting A-G in a perfect balancing order.

> i d
d (*)

> i b
  b
d (*)

> i a
    a
  b
d (*)

> i c
    a
  b
    c
d (*)

> i f
    a
  b
    c
d (*)
  f

> i e
    a
  b
    c
d (*)
    e
  f

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

You would always get a perfectly balanced tree if you entered the median of the range of numbers then the median of the range of numbers lower then the first number and so on.


Right Skew -> Left 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]

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

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

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

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

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

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

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

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

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

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

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

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

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

>


Right Skew -> Balance

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

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

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

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

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

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

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

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

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

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

>

Add elements and Balance

> i 1
1 (*)

> i 2
1 (*)
  2

> i 3
1 (*)
  2
    3

> i 4
1 (*)
  2
    3
      4

> i 5
1 (*)
  2
    3
      4
        5

> i 6
1 (*)
  2
    3
      4
        5
          6

> i 7
1 (*)
  2
    3
      4
        5
          6
            7

> balance
    1
  2
    3
4 (*)
    5
  6
    7

> i 8
    1
  2
    3
4 (*)
    5
  6
    7
      8

> i 9
    1
  2
    3
4 (*)
    5
  6
    7
      8
        9

> r
    1
  2
    3
4
    5
  6 (*)
    7
      8
        9

> r
    1
  2
    3
4
    5
  6
    7 (*)
      8
        9

> rr
    1
  2
    3
4
    5
  6
    7 (*)
      8
        9

> rl
    1
  2
    3
4
    5
  6
      7 (*)
    8
      9

>