2016-10-23 20 views
0

私は次のバイナリツリーを持っています。これは、ツリーの回転の最小回数を使ってターゲットバイナリツリー(ポストの2番目のツリー)に変換しようとしています。このツリーの理論回転数の最小値は5ですが、最小値は6回転です。ローテーションもコピーしました。何が欠けていますか?2つのバイナリツリー間の回転距離

ツリー: 1 \ \ 3 /\ / \ 2 5 / \ / \ 4 7 / \ / \ 6 11 /\ / \ 9 12 /\ 8 10

ターゲットツリー:私は(6つの回転を必要とすべてが)これまでに試してみました 1 \ \ 11 / \ / \ 9 12 /\ / \ 3 10 /\ / \ 2 5 /\ / \ 4 7 /\ 6 8

回転:

Order1: 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 Order2: 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

Order3: 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

Order4: 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

Order5:

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

答えて

1

回転右のw i番目のルート11とピボット9
回転は回転し、ルート5と左ピボット9
回転が回転ルート9およびピボット11

と左ルート3とピボット9
と左ルート7と左ピボット9
関連する問題