J* E* C* N* U* N* S* ›› 2025, Vol. 2025 ›› Issue (5): 32-42.doi: 10.3969/j.issn.1000-5641.2025.05.004

• AI-Enabled Open Source Technologies and Applications • Previous Articles     Next Articles

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

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

CLC Number: