两棵二叉树之间的旋转距离
Rotation distance between two binary trees
我有以下二叉树,我正在尝试使用最小数量的树旋转将其转换为目标二叉树(post 中的第二棵树)。这棵树的理论最小旋转数是 5,然而,我能计算出的最小值是 6 旋转,我也复制了旋转,我错过了什么?
树:
1
\
\
3
/ \
/ \
2 5
/ \
/ \
4 7
/ \
/ \
6 11
/ \
/ \
9 12
/ \
8 10
目标树:
1
\
\
11
/ \
/ \
9 12
/ \
/ \
3 10
/ \
/ \
2 5
/ \
/ \
4 7
/ \
6 8
到目前为止我尝试过的轮换(都需要6轮):
订单 1:
Rotate left with root 7 and pivot 11
Rotate left with root 5 and pivot 11
Rotate left with root 3 and pivot 11
Rotate left with root 7 and pivot 9
Rotate left with root 5 and pivot 9
Rotate left with root 3 and pivot 9
订单 2:
Rotate left with root 7 and pivot 11
Rotate left with root 5 and pivot 11
Rotate left with root 7 and pivot 9
Rotate left with root 3 and pivot 11
Rotate left with root 5 and pivot 9
Rotate left with root 3 and pivot 9
订单 3:
Rotate left with root 7 and pivot 11
Rotate left with root 5 and pivot 11
Rotate left with root 7 and pivot 9
Rotate left with root 5 and pivot 9
Rotate left with root 3 and pivot 11
Rotate left with root 3 and pivot 9
订单 4:
Rotate left with root 7 and pivot 11
Rotate left with root 7 and pivot 9
Rotate left with root 5 and pivot 11
Rotate left with root 3 and pivot 11
Rotate left with root 5 and pivot 9
Rotate left with root 3 and pivot 9
订单 5:
Rotate left with root 7 and pivot 11
Rotate left with root 7 and pivot 9
Rotate left with root 5 and pivot 11
Rotate left with root 5 and pivot 9
Rotate left with root 3 and pivot 11
Rotate left with root 3 and pivot 9
以根 11 和轴 9 向右旋转
以根 7 和枢轴 9 向左旋转
以根5和枢轴9向左旋转
以根 3 和枢轴 9 向左旋转
以根 9 和枢轴 11 向左旋转
我有以下二叉树,我正在尝试使用最小数量的树旋转将其转换为目标二叉树(post 中的第二棵树)。这棵树的理论最小旋转数是 5,然而,我能计算出的最小值是 6 旋转,我也复制了旋转,我错过了什么?
树:
1
\
\
3
/ \
/ \
2 5
/ \
/ \
4 7
/ \
/ \
6 11
/ \
/ \
9 12
/ \
8 10
目标树:
1
\
\
11
/ \
/ \
9 12
/ \
/ \
3 10
/ \
/ \
2 5
/ \
/ \
4 7
/ \
6 8
到目前为止我尝试过的轮换(都需要6轮):
订单 1:
Rotate left with root 7 and pivot 11
Rotate left with root 5 and pivot 11
Rotate left with root 3 and pivot 11
Rotate left with root 7 and pivot 9
Rotate left with root 5 and pivot 9
Rotate left with root 3 and pivot 9
订单 2:
Rotate left with root 7 and pivot 11
Rotate left with root 5 and pivot 11
Rotate left with root 7 and pivot 9
Rotate left with root 3 and pivot 11
Rotate left with root 5 and pivot 9
Rotate left with root 3 and pivot 9
订单 3:
Rotate left with root 7 and pivot 11
Rotate left with root 5 and pivot 11
Rotate left with root 7 and pivot 9
Rotate left with root 5 and pivot 9
Rotate left with root 3 and pivot 11
Rotate left with root 3 and pivot 9
订单 4:
Rotate left with root 7 and pivot 11
Rotate left with root 7 and pivot 9
Rotate left with root 5 and pivot 11
Rotate left with root 3 and pivot 11
Rotate left with root 5 and pivot 9
Rotate left with root 3 and pivot 9
订单 5:
Rotate left with root 7 and pivot 11
Rotate left with root 7 and pivot 9
Rotate left with root 5 and pivot 11
Rotate left with root 5 and pivot 9
Rotate left with root 3 and pivot 11
Rotate left with root 3 and pivot 9
以根 11 和轴 9 向右旋转
以根 7 和枢轴 9 向左旋转
以根5和枢轴9向左旋转
以根 3 和枢轴 9 向左旋转
以根 9 和枢轴 11 向左旋转