質問: avl tree insert問題 我知道avl的定義 但是今天拿到一個題目是這樣的 mar / \ aug may / \ \ apr jan nov / \ dec july 請問 insert feb 的結果為何? 因為是初學者,可能我觀念還不通 所以請解釋一下步驟,謝謝!
回答: (0) initial avl tree mar / \ aug may / \ \ apr jan nov / \ dec july (1) insert feb mar / \ aug may / \ \ apr jan nov / \ dec july \ feb (2) becaue aug subtree is not avl and it is in r-l case, right rotate the right subtree (jan subtree) then a left rotate of aug subtree mar / \ aug may / \ \ apr dec nov / \ (empty ) jan / \ feb july mar / \ dec may / \ \ aug jan nov / \ / \ apr(empty )feb july