3 Replies - 6637 Views - Last Post: 24 March 2010 - 03:06 PM Rate Topic: -----

#1 Djhar  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 35
  • Joined: 24-January 10

Binary Tree Rotation

Posted 24 March 2010 - 02:08 PM

Hey guys,

I am trying to start this problem dealing with rotating a tree to the left and printing it with proper indentation but I'm confused as to how this is going to work. The binary tree is show as follows:

                    10
                   /  \
                  5   20
                 / \
                2   7
                   /
                  6 



and the output needs to be:
                    20
                   
                 10
                        7
                            6
                     5       
                          2


I can see that the 20 replaces the 10, the 10 replaces the 5, the 5 replaces the 2 and so on.. however in the textbook the output is exactly as I printed it- with no lines connecting the nodes. Any help is highly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Binary Tree Rotation

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Binary Tree Rotation

Posted 24 March 2010 - 02:34 PM

I don't understand why there were no lines at the output tree, but nevertheless I assume you are having trouble with the algorithm.
So:
http://en.wikipedia....i/Tree_rotation
Was This Post Helpful? 0
  • +
  • -

#3 Djhar  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 35
  • Joined: 24-January 10

Re: Binary Tree Rotation

Posted 24 March 2010 - 02:40 PM

View PostPennyBoki, on 24 March 2010 - 01:34 PM, said:

I don't understand why there were no lines at the output tree, but nevertheless I assume you are having trouble with the algorithm.
So:
http://en.wikipedia....i/Tree_rotation


The algorithm part of it I understand but I just don't know how to go about writing this code. And don't get me wrong, I'm not asking for it to be written for me. I just need a clear explanation as to how it goes from the original tree to the output tree as I shown above. Wikipedia doesn't always cut it =/
Was This Post Helpful? 0
  • +
  • -

#4 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Binary Tree Rotation

Posted 24 March 2010 - 03:06 PM

I see. Well do you know how to make a binary tree in code? Or are you having trouble with the screen formatting, i.e. the display of the tree?

Iterate through the tree, breadth first search so that you can print it in a proper way.
Then create the new tree based on the rotating algorithm that you already know, and then just as the previous print it.

This post has been edited by PennyBoki: 24 March 2010 - 03:08 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1