华东师范大学学报(自然科学版) ›› 2025, Vol. 2025 ›› Issue (5): 32-42.doi: 10.3969/j.issn.1000-5641.2025.05.004

• AI赋能的开源技术与应用 • 上一篇    下一篇

基于智能体的可交互数据结构和算法可视化实现

庞瑞洋, 陆雪松*()   

  1. 华东师范大学 数据科学与工程学院, 上海 200062
  • 收稿日期:2025-06-27 出版日期:2025-09-25 发布日期:2025-09-25
  • 通讯作者: 陆雪松 E-mail:xslu@dase.ecnu.edu.cn
  • 基金资助:
    国家重点研发计划 (2023YFC3341200); 国家自然科学基金 (62277017)

Interactive data structure and algorithm visualization based on AI agents

Ruiyang PANG, Xuesong LU*()   

  1. School of Data Science and Engineering, East China Normal University, Shanghai 200062, China
  • Received:2025-06-27 Online:2025-09-25 Published:2025-09-25
  • Contact: Xuesong LU E-mail:xslu@dase.ecnu.edu.cn

摘要:

数据结构与算法 (Data Structure and Algorithm, DSA) 作为计算机教育的核心课程, 在培养学生的编程能力与算法思维方面起着关键作用. 可视化在DSA教学中可以起到提高教学效率和加深学生理解的重要作用. 然而, 现有的DSA可视化工具大多依赖人工编写可视化代码, 存在覆盖范围有限、更新成本高和缺乏交互性等局限性, 难以满足动态演示与个性化教学的需求. 随着大型语言模型 (Large Language Model, LLM) 在代码生成方面的出色表现, 基于LLM实现自动化的DSA可视化成为可能. 为此, 提出了一种基于ReAct (Reasoning and Acting)智能体的交互式可视化代码生成方法, 旨在解决传统可视化工具自动化程度低、交互性不足的问题. 该方法结合LLM的代码生成能力和DSV (Data Structure Visualization)平台的接口, 能够将基于Python编写的DSA代码转换为可交互、可执行的动态可视化的代码, 从而提升教学直观性和学习体验. 为系统评估该方法的有效性, 构建了包含150对DSA代码及其对应的DSV可视化代码的数据集, 并对比了3种方法 (直接提示、思维链提示、ReAct智能体) 在多种主流LLM上的表现. 实验结果显示, 所提出的基于ReAct智能体的方法在编译通过率 (Compilation Rate, CR)、执行通过率 (Execution Rate, ER)和可用率 (Usability Rate, UR) 这3项指标上均显著优于其他方法, 尤其在DeepSeek-R1模型下表现最优, 显著提升了生成可视化代码的准确性与可交互性, 验证了结合LLM与智能体框架在DSA可视化教学中的可行性与优势, 为构建高效、个性化、自动化的计算机编程教学工具提供了新路径.

关键词: 数据结构与算法可视化, 大语言模型, 智能体, 代码生成

Abstract:

Data structures and algorithms (DSA), as a core course in computer science education, play a key role in cultivating programming skills and algorithmic thinking of students. Visualization can significantly enhance teaching effectiveness and deepen student understanding in DSA education. However, existing DSA visualization tools often rely on manually written visualization codes that lead to limitations such as limited coverage, high maintenance costs, and lack of interactivity; hence, the needs of dynamic demonstrations and personalized teaching are difficult to meet. With the outstanding performance of large language models (LLMs) in code generation, automated DSA visualization has become a promising possibility. Therefore, this study proposed an interactive visualization code generation method based on the reasoning and acting (ReAct) AI agent framework, aiming to address the low automation and insufficient interactivity of traditional visualization tools. By leveraging the code generation capabilities of LLMs and integrating with the data structure visualization (DSV) platform interface, the proposed method transformed Python-based DSA code into interactive, executable, and dynamically visualized code, thereby enhancing teaching clarity and learning experience. To systematically evaluate the effectiveness of the method, we constructed a dataset of 150 pairs of DSA code and corresponding DSV visualization code and compared three approaches—direct prompting, chain-of-thought prompting, and the ReAct AI agent approach—across several mainstream LLMs. The experimental results showed that the proposed ReAct AI agent-based method significantly outperformed the other approaches in terms of the compilation rate, execution rate, and usability rate, with the best performance observed in the DeepSeek-R1 model. This demonstrated notable improvements in the accuracy and interactivity of generated visualization code. This research confirms the feasibility and advantages of integrating LLMs with agent frameworks in DSA visualization teaching, offering a novel path toward building efficient, personalized, and automated tools for computer programming education.

Key words: data structure and algorithm visualization, large language model, AI agent, code generation

中图分类号: