NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Can Graph Descriptive Order Affect Solving Graph Problems with LLMs?

Yuyao Ge, Shenghua Liu, Baolong Bi, Yiwei Wang, Lingrui Mei, Wenjie Feng, Lizhe Chen, Xueqi Cheng

Abstract

Large Language Models (LLMs) have demonstrated significant capabilities in logical reasoning, yet graph-based problems remain a persistent challenge. This paper investigates the impact of the sequential order in which graph edges are described to an LLM. By transitioning from random edge lists to structured traversal-based or probability-based orders, we observe substantial performance gains. Our findings reveal an "attention bias" in LLMs, where the linear presentation of non-linear data dictates the model's reasoning success.

Introduction

Graphs are inherently non-linear structures, but LLMs process information as linear sequences of text. Traditionally, graph encoding research has focused on the format (e.g., adjacency lists vs. natural language) or prompting techniques like Chain-of-Thought (CoT). However, the sequential order of edge descriptions—a factor often left to chance—plays a critical role in how models perceive graph topology.

Comparison of Random vs. BFS descriptive orders for a cycle detection task, showing a significant accuracy increase with structured ordering.

As shown in Figure 1, simply reordering the edge list from a random sequence to a Breadth-First Search (BFS) order can improve accuracy in cycle detection by over 8%. This suggests that the "perspective" provided by the input sequence can either align with or hinder the model's internal reasoning process.

Methodology and Benchmark

To systematically evaluate this phenomenon, we introduced GraphDO (Graph Description with Order), a benchmark comprising 8,500 cases across six tasks: Connectivity, Cycle Detection, Hamilton Path, Shortest Path, Topological Sort, and Node Classification.

We tested four primary ordering strategies:

  1. Traversal-based: BFS (hierarchical) and DFS (recursive).
  2. Probability-based: PageRank (global importance) and Personalized PageRank (local importance).

These were evaluated across six mainstream LLMs (including GPT-3.5-Turbo and LLaMA2) using various prompting styles, including a novel "CoT-BAG" (Build-A-Graph) method that encourages the model to reconstruct the graph mentally.

Key Insights: The Attention Bias

The core discovery is the presence of an "Attention Bias." LLMs tend to prioritize certain sections of the input based on their position in the sequence. Structured ordering mitigates this by aligning the input with the logical steps required for a specific task.

There is a clear Task-Order Synergy:

  • BFS is optimal for local connectivity tasks like Shortest Path and Connectivity because it describes the graph in expanding concentric circles.
  • DFS excels in global, path-dependent tasks such as finding a Hamilton Path or performing a Topological Sort, as it forces the model to follow a continuous path to its end.

Quantitative Results

The impact of descriptive order is most pronounced in complex tasks. While simple connectivity checks are relatively robust, tasks like finding a Hamilton Path show massive variance depending on the order used.

Average accuracy across different graph tasks using various ordering strategies. BFS and DFS show clear advantages depending on the task type.

As illustrated in Figure 5, BFS achieved a peak accuracy of 89.43% for connectivity tasks, while DFS outperformed the random baseline in Hamilton Path tasks by a staggering 66.4%. In cycle detection, switching to BFS order resulted in an average accuracy improvement of 12.73% across models.

Conclusion and Future Work

The order of graph description is a vital, yet previously overlooked, hyperparameter in LLM reasoning. By matching the descriptive order to the task's inherent logic, we can significantly boost model performance without additional training.

Future work will focus on automatically determining the optimal order for arbitrary tasks and investigating the underlying transformer mechanics that drive this attention bias. We also aim to scale these findings to larger, more complex graph structures beyond the 50-node limit explored in this study.

Summary updated

BibTeX
@inproceedings{ge2025can,
  author = {Yuyao Ge and Shenghua Liu and Baolong Bi and Yiwei Wang and Lingrui Mei and Wenjie Feng and Lizhe Chen and Xueqi Cheng},
  title = {{Can Graph Descriptive Order Affect Solving Graph Problems with LLMs?}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure