# Demo 1:碰撞 BHT > 第 11 章 查询复杂度 · [本章演示](index.md) · [代码演示总索引](../index.md) **可视化**:双图 —— N=8 标记命中 + log-log 查询数对比 **对应教程**:[第 11 章 查询复杂度 中相关小节](https://tutorial.chenzhaoyun.com/quantum-tutorial/ch11-query-complexity/) · 依赖安装:`pip install "unified-quantum[visualization,simulation]"` ## 实现要点 核心:在 N=8 的二对一承诺函数 f=[0,0,1,1,2,2,3,3] 上演示 Brassard-Hoyer-Tapp 抽样表 + Grover 算法的 r = N^(1/3) 平衡点。画三幅图: (左) hash 函数结构 + 抽样表 + "另一半"原像标记 (中) 经典生日攻击 sqrt(N) vs 量子 BHT N^(1/3) 查询数 log-log 对比 (右) N=8 实际跑 Grover: 命中 marked 状态的概率分布 ## 完整源码 ```{literalinclude} 01_collision_bht.py :language: python :linenos: :caption: demos/ch11-query-complexity/01_collision_bht.py ``` ## 运行结果 ![Demo 1:碰撞 BHT](01_collision_bht.png) ## 运行方式 ```bash # 仓库根目录执行;输出 PNG 到 demos/ch11-query-complexity/01_collision_bht.png,关键统计到 stdout .venv/bin/python3 demos/ch11-query-complexity/01_collision_bht.py ``` --- [← 本章演示](index.md) · [↑ 代码演示总索引](../index.md) · [⌂ 教程门户](https://tutorial.chenzhaoyun.com/)