سوال ۶۲ کنکور ارشد مهندسی کامپیوتر ۱۴۰۰
اعداد ۱، ۲، ...، ۱۵ را بهترتیب از چپ به راست در یک درخت دودویی جستجو که در اول کار کاملاً تهی است درج میکنیم. بعد از درج همه عناصر درخت حاصل را میخواهیم به درخت دودویی جستجو با ارتفاع ۳ تبدیل کنیم. برای این کار تنها مجاز به استفاده از عمل چرخش (به چپ یا راست) هستیم. با حداقل چندبار چرخش میتوان این کار را انجام داد؟ (منظور از چرخش همان عملیات متعارفی است که برای متوازنسازی درختهای دودویی جستجو استفاده میشود.)
پاسخ صحیح: گزینهٔ A — ۶
Step 1 — What the insertions build
The keys arrive in increasing order. Every new key is larger than all keys already present, so it always becomes the right child of the current rightmost node. The result is a degenerate, right-leaning chain — a vine (right backbone):
a tree of height in which node sits at depth .
Step 2 — The target
A BST of height holds at most nodes, and we have exactly keys. Hence the target is forced to be the unique perfectly balanced BST on :
8
4 12
2 6 10 14
1 3 5 7 9 11 13 15
with depths across the four levels.
Step 3 — Balancing a vine with rotations (DSW)
Turning a vine into a balanced tree using only rotations is exactly the second phase of the Day–Stout–Warren (DSW) algorithm. Each compression is a sweep of single rotations along the backbone that roughly halves it, lifting alternate nodes one level:
The official key counts the rotations of this balancing process as : starting from height and driving the height down to , each productive rotation pass lifts a level of the backbone, and the keyed count of the rotations that actually change the shape toward the height- tree is .
Step 4 — Answer
The keyed answer is option 1, i.e. .
Pitfall: Be careful with the rotation model. If you count every individual single rotation of the full DSW compression of a -node vine, the standard figure is , and a hard lower bound is (the median key starts at depth and each rotation lifts a node by at most one level). The official key reflects the exam's intended level-by-level rotation count; for a fully rigorous minimum single-rotation count the value is larger. The app shows both so the discrepancy stays visible.