Talk:Tree rotation

From Wikipedia, the free encyclopedia

[edit] New Caption Doesn't Match New Illustration

gandoo First off I want to say that I like the new illustration. It's much prettier and more informative than the simple ascii art it replaced. The caption doesn't seem to fit it according to my definition, however. I would say that the right rotation is performed with 'Q' as the root and, thus, the rotation is on, or rooted at, 'Q'. The left rotation is the one rooted at 'P'. Is this a mistake or merely a convention unfamiliar to me?

--Waylonflinn 18:59, 28 August 2006 (UTC)

== Python code hard to read ==yatindra nath yadav


sdwedsdsd

The python code is very hard to read. A simplification would be expedient in this case.

I agree, it's quite obscure to anyone not familiar with tuples. That said, the diagrams seem clear enough to enable implementation in any language. Deco 05:17, 29 July 2005 (UTC)

I'm afraid that Python code is my fault, from 2001. Here's a shorter version, but I'm not sure what makes either version harder to read:

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

Apparently I'm now so indoctrinated with Python that I have forgotten what it was like to not know it! How about this?

   def right_rotation(node):
       delendum = node.left_child
       new_right_child = binary_tree_node(left_child=delendum.right_child, 
           key=node.key, right_child=node.right_child)
       return binary_tree_node(left_child=delendum.left_child, 
           key=delendum.key, right_child=new_right_child)

A version with shorter variable names:

   def right_rotation(N):
       D = N.L
       R = node(L=D.R, K=N.K, R=N.R)
       return node(L=D.L, K=D.K, R=R)

My point, by the way, is not to defend Python as a notation, but to figure out what would be an improvement.

-- Kragen

  • imho the python code is quite readable and i am only a bit familiar with python by having played with it for 2 days. i also think familarity with tuples can be expected from readers interested in trees. but another thing: although it is more or less obvious it would be nice to have left_rotation(treenode) also for completeness. -- wizzar 22:45, 18 December 2005 (UTC)


I think what we should shoot for is consistency between this article, Binary tree, Red-Black tree and related articles.

--Waylonflinn 20:57, 28 August 2006 (UTC)


Thanks Waylonflinn for that, and between, i agree with the change in the explanation, which slightly misleads and needs a fix. And, how about switching to C for the example rather than in python?

--Ramasamy 18:00, 01 September 2006 (IST)

[edit] Left Right confusion

I'm coming across sources which say that the direction of a rotation is not the side upon which the nodes are being shifted, as illustrated on this page, but depends on which child of the node being rotated is going to be the parent. These are 2 completely different views. Who is wrong?

Isn't the psudeo code wrong?