Splay Tree Split
1. **State the problem:** We need to construct a splay tree with height 6 containing 10 elements, with the element 7 at level 6. Then, perform a split operation at the value 7.
2. **Constructing the splay tree:** A tree with height 6 means the longest root-to-leaf path has 6 edges (levels numbered from root at 1).
We want 10 elements, numbered 1 through 10 for convenience.
We arrange so that element 7 is at level 6. For example:
- Root is 1 (level 1)
- Right child 2 (level 2)
- Right child 3 (level 3)
- Right child 4 (level 4)
- Right child 5 (level 5)
- Right child 7 (level 6)
- Left child of 7 is 6
- Right child of 7 is 8, and then 9 and 10 as right descendants
This makes the height 6 with 7 at level 6.
3. **Visual approximation:**
1
\
2
\
3
\
4
\
5
\
7
/ \
6 8
\
9
\
10
4. **Performing the split at 7:** The split operation splits the tree into two trees: elements less than 7 and elements greater than or equal to 7. In splay trees, this is typically done by splaying the node with key 7 to the root.
**Steps to splay 7 to root:**
- Starting at node 7, perform successive zig rotations:
- Zig-zig rotations between 5 and 7, then between 3 and 5, and so on until 7 reaches the root.
Detailed splaying steps:
- Step 1: Zig-zig at 5 and 7
- Step 2: Zig-zig at 3 and 5
- Step 3: Zig-zig at 1 and 3
After splaying, 7 is the root.
5. **Resulting tree:**
Root 7 with left subtree of {1,2,3,4,5,6} and right subtree of {8,9,10}.
6. **Split:**
- The left tree contains keys less than 7: {1,2,3,4,5,6}
- The right tree contains keys greater than or equal to 7: {7,8,9,10}
**Final**
**Left subtree (keys <7):** Rooted at 6 (splayed below 7 during rotation)
**Right subtree (keys ≥7):** Root is 7 with right children 8, 9, 10
This completes the split operation at 7.