SE250:lab-7:jsmi233

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

Playing with balanced binary search tree's

I inserted the words 'hello' 'world' 'from' 'a' 'binary' 'search' 'tree'

The resulting tree:

--a

---binary

-from

hello

--search

---tree

-world


Random lol interlude

Lolz!!!!!!!!!!!!!!!!!!!!!!!!!!!

Clear tree = crash!!!!!!!!!

Teh code failz!!!!!!!!!!!!!!


Back to work

Inserting the elements dbacfeg in any order will result in a balanced tree provided the following conditions are met: 'd' comes first, 'b' comes before 'a' and 'c', and 'f' comes before 'e' and 'g'. The reason for these conditions is that a parent must be inserted before its children. I estimate that there are fifty six different insertion combinations that result in a balanced tree.


Starting from a right skew, repeatedly use "rotate left" and then "root" to bring the tree into a left skew format.


Starting from a right skew, use the following combination of commands to balance the tree:

-{Rotate left, parent} three times

-left, rotate right, parent

-right, rotate left, parent


From a balanced tree (seven elements), if two more elements (greater than all current elements) are added to the tree, then the tree can be rebalanced with the commands: right, right, rotate left.