00-Treap-03-分裂合并.svg 2.3 KB

1234567
  1. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 920 320" role="img" aria-labelledby="title desc">
  2. <title id="title">FHQ Treap 的 split 与 merge</title><desc id="desc">一棵树按键四分成键不大于四和键大于四的两棵树,再按优先级合并。</desc>
  3. <style>text{font-family:system-ui,sans-serif;fill:#172033}.edge{stroke:#64748b;stroke-width:3}.node{fill:#eff6ff;stroke:#2563eb;stroke-width:3}.left{fill:#dcfce7;stroke:#16a34a;stroke-width:3}.right{fill:#ffedd5;stroke:#ea580c;stroke-width:3}.arr{stroke:#d97706;stroke-width:4;fill:none}.note{font-size:17px}.label{font-size:18px;font-weight:700}</style>
  4. <text x="24" y="28" class="note">split(root,4):键 ≤4 去左树,键 >4 去右树;merge 再由优先级决定根。</text>
  5. <text x="100" y="65" class="note">原树</text><line class="edge" x1="155" y1="105" x2="105" y2="155"/><line class="edge" x1="155" y1="105" x2="205" y2="155"/><line class="edge" x1="205" y1="155" x2="235" y2="205"/><circle class="node" cx="155" cy="105" r="25"/><circle class="node" cx="105" cy="155" r="25"/><circle class="node" cx="205" cy="155" r="25"/><circle class="node" cx="235" cy="205" r="25"/><text class="label" x="148" y="112">4</text><text class="label" x="98" y="162">2</text><text class="label" x="198" y="162">7</text><text class="label" x="228" y="212">5</text><path class="arr" d="M270 145 L360 145" marker-end="url(#a)"/>
  6. <text x="395" y="65" class="note">左半(≤4)</text><circle class="left" cx="445" cy="105" r="25"/><circle class="left" cx="390" cy="165" r="25"/><line class="edge" x1="445" y1="105" x2="390" y2="165"/><text class="label" x="438" y="112">4</text><text class="label" x="383" y="172">2</text><text x="580" y="65" class="note">右半(>4)</text><circle class="right" cx="650" cy="105" r="25"/><circle class="right" cx="705" cy="165" r="25"/><line class="edge" x1="650" y1="105" x2="705" y2="165"/><text class="label" x="643" y="112">7</text><text class="label" x="698" y="172">5</text><path class="arr" d="M520 250 L615 250" marker-end="url(#a)"/><text x="466" y="278" class="note">merge:比较两根优先级</text><defs><marker id="a" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path d="M0 0 L10 5 L0 10z" fill="#d97706"/></marker></defs>
  7. </svg>