# Demo 2:元素唯一性 > 第 11 章 查询复杂度 · [本章演示](index.md) · [代码演示总索引](../index.md) **可视化**:双图 —— toy 数组 + O(N) vs O(N^{2/3}) + Johnson 平衡 **对应教程**:[第 11 章 查询复杂度 中相关小节](https://tutorial.chenzhaoyun.com/quantum-tutorial/ch11-query-complexity/) · 依赖安装:`pip install "unified-quantum[visualization,simulation]"` ## 实现要点 核心:对玩具数组 arr = [3, 1, 4, 1, 5, 9, 2, 6] (idx=1,3 重复值 1) 演示 Ambainis 量子行走算法的 N^{2/3} 平衡点。画三幅图: (左) 数组可视化 + 标记重复对 (中) N=8..10^5 查询数对比: 经典 O(N) vs Grover sqrt(N) vs 量子 O(N^{2/3}) (右) Johnson 图参数平衡 (固定 N=1000): epsilon, delta, 总成本 vs r 并用 uniqc 跑 4 个 1-qubit oracle 验证 arr[idx] == 1 的检测能力。 ## 完整源码 ```{literalinclude} 02_element_distinctness.py :language: python :linenos: :caption: demos/ch11-query-complexity/02_element_distinctness.py ``` ## 运行结果 ![Demo 2:元素唯一性](02_element_distinctness.png) ## 运行方式 ```bash # 仓库根目录执行;输出 PNG 到 demos/ch11-query-complexity/02_element_distinctness.png,关键统计到 stdout .venv/bin/python3 demos/ch11-query-complexity/02_element_distinctness.py ``` --- [← 本章演示](index.md) · [↑ 代码演示总索引](../index.md) · [⌂ 教程门户](https://tutorial.chenzhaoyun.com/)