Ask Your Question

Revision history [back]

The documentation of the left_rotate method starts with:

Left rotation on binary trees is defined as follows: Let T be a
binary tree such that the right child of the root of T is a node.

In the error happens when the following tree shows up:

sage: t
[[., [., .]], .]
sage: ascii_art(t)

  o
 /
o
 \
  o

So, indeed the right child of the root of t is not a node:

sage: ascii_art(t.left_rotate())
...
IndexError: list index out of range

sage: ascii_art(t.right_rotate())

o
 \
  o
 /
o

The documentation of the left_rotate method starts with:

Left rotation on binary trees is defined as follows: Let T be a
binary tree such that the right child of the root of T is a node.

In the error happens when the following tree shows up:

sage: t
[[., [., .]], .]
sage: ascii_art(t)

  o
 /
o
 \
  o

So, indeed the right child of the root of t is not a node:

sage: ascii_art(t.left_rotate())
...
IndexError: list index out of range

sage: ascii_art(t.right_rotate())

o
 \
  o
 /
o

I agree that the error could be more explicit.