Science Fair Projects Ideas - Tree rotation

All Science Fair Projects

      

Science Fair Project Encyclopedia for Schools!

  Search    Browse    Forum  Coach    Links    Editor    Help    Tell-a-Friend    Encyclopedia    Dictionary     

Science Fair Project Encyclopedia

For information on any area of science that interests you,
enter a keyword (eg. scientific method, molecule, cloud, carbohydrate etc.).
Or else, you can start by choosing any of the categories below.

Tree rotation

A tree rotation is an operation on a binary search tree that changes the structure without interfering with the order of the elements. A tree rotation moves one node up in the tree and one node down. They are used to change the shape of the tree, and in particular to decrease its height by moving smaller subtrees down and larger subtrees up, resulting in improved performance of many tree operations.

Examples

The tree

       D
      / \
     /   \
    B     E
   / \
  A   C

can be rotated to look like

     B
    / \
   /   \
  A     D
       / \ 
      C   E 

This is called a right rotation. Going from the second tree to the first would be a left rotation.

If we write our tree nodes as (left subtree, nodevalue, right subtree), then the first structure is ((A, B, C), D, E), and the second is (A, B, (C, D, E)), and computing one from the other is very simple. The following is example Python code that performs that computation:

def right_rotation(treenode):
    left, D, E = treenode
    A, B, C = left
    return (A, B, (C, D, E))

There are also "double left" and "double right" rotations, which can be written as compositions of left and right rotations.

Tree rotations are used in a number of tree data structures such as AVL trees, red-black trees, and splay trees. They require only constant time because they are local transformations: they only operate on 5 nodes, and need not examine the rest of the tree.

References

09-23-2007 01:00:40
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
Science kits, science lessons, science toys, maths toys, hobby kits, science games and books - these are some of many products that can help give your kid an edge in their science fair projects, and develop a tremendous interest in the study of science. When shopping for a science kit or other supplies, make sure that you carefully review the features and quality of the products. Compare prices by going to several online stores. Read product reviews online or refer to magazines.

Start by looking for your science kit review or science toy review. Compare prices but remember, Price $ is not everything. Quality does matter.
Science Fair Coach
What do science fair judges look out for?
ScienceHound
Science Fair Projects for students of all ages
All Science Fair Projects.com Site
All Science Fair Projects Homepage
Search | Browse | Links | From-our-Editor | Books | Help | Contact | Privacy | Disclaimer | Copyright Notice