分步生成算法可视化,避免大模型幻觉导致的错误。
ALGOGEN: Tool-Generated Verifiable Traces for Reliable Algorithm Visualization

- 先用代数语言描述算法状态变化,再生成可验证的执行轨迹。
- 在LeetCode 200题上成功率提升17.3%,达99.8%。
- 适合教育科技、自动教学系统开发者使用。
算法可视化(AV)通过动画呈现算法执行过程,帮助学生构建心智模型。当前基于大模型的方法(如CODE2VIDEO)采用端到端生成视频,但需同时完成算法模拟与渲染约束(如布局、配色),任务复杂导致大模型幻觉频发,引发执行失败、元素重叠和帧间不一致。为此,我们提出ALGOGEN新范式:将算法执行与渲染解耦。首先定义可视化轨迹代数(VTA),构建算法状态与操作的幺半群;大模型生成Python追踪器,输出符合VTA的JSON格式轨迹;再通过渲染风格语言(RSL)模板化布局,由确定性渲染器将轨迹与RSL结合,生成Manim、LaTeX/TikZ或Three.js代码。在包含200个任务的LeetCode AV基准测试中,相比端到端方法,成功率达99.8%(提升17.3%),显著优于82.5%。结果表明,该解耦范式有效缓解复杂任务中的大模型幻觉,提供更可靠的自动化高质量算法可视化方案。演示视频与代码已开源。
原文摘要 · Abstract (English)
Algorithm Visualization (AV) helps students build mental models by animating algorithm execution states. Recent LLM-based systems such as CODE2VIDEO generate AV videos in an end-to-end manner. However, this paradigm requires the system to simultaneously simulate algorithm flow and satisfy video rendering constraints, such as element layout and color schemes. This complex task induces LLM hallucinations, resulting in reduced execution success rates, element overlap, and inter-frame inconsistencies. To address these challenges, we propose ALGOGEN, a novel paradigm that decouples algorithm execution from rendering. We first introduce Visualization Trace Algebra (VTA), a monoid over algorithm visual states and operations. The LLM then generates a Python tracker that simulates algorithm flow and outputs VTA-JSON traces, a JSON encoding of VTA. For rendering, we define a Rendering Style Language (RSL) to templatize algorithm layouts. A deterministic renderer then compiles algorithm traces with RSL into Manim, LaTeX/TikZ, or Three.js outputs. Evaluated on a LeetCode AV benchmark of 200 tasks, ALGOGEN achieves an average success rate improvement of 17.3% compared to end-to-end methods, with 99.8% versus 82.5%. These results demonstrate that our decoupling paradigm effectively mitigates LLM hallucinations in complex AV tasks, providing a more reliable solution for automated generation of high-quality algorithm visualizations. Demo videos and code are available in the project repository.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。