How can I compute a vertex permutation with a “prefix-neighbors” property in polynomial time?
Difference between en2 and en3, changed 77 character(s)
I have an undirected graph  and I need to reorder its vertices into a permutation  that satisfies the following “prefix-neighbors” property:↵

> Property: For every vertex v_i (with i > 0) in the permutation, if there exists any vertex v_j (with j < i) that is adjacent to v_i (i.e., (v_j, v_i) is an edge in E), then every vertex v_k with k < j must also be adjacent to v_i.↵

In other words, if  has any neighbors among the vertices that come before it in the ordering, then those neighbors must form a contiguous block starting from the very first vertex in the ordering.↵

For example, consider a graph with vertices  and edges:
 (0,1) (0,2) (1,3) (2,3)↵

      0↵
     / \↵
    1   2↵
     \ /↵
      3↵


One valid ordering is :↵

- Vertex 1: Placed first, so no condition applies.↵
- Vertex 2: Placed second; if it has any neighbor among vertices before it, then the very first vertex must be adjacent—but here it happens that 2 is not adjacent to 1, so the condition is not triggered.↵
- Vertex 0: Placed third; its neighbors among  are 1 and 2. The earliest (lowest-index) neighbor is 1, which is at the beginning of the ordering.↵
- Vertex 3: Placed last; its neighbors among  are 1 and 2 (its first neighbor is 1 at index 0), so the condition is satisfied.↵


My questions are:↵

1. Algorithm & Complexity: Is it possible to compute such a permutation in  time?↵
2. Approach:What algorithm would you recommend for this problem?↵
3. Uniqueness:Under what conditions is such an ordering unique, and how can I detect if multiple valid orders exist or if no valid ordering exists?↵

Any algorithm sketches, insights, or sample code in Python or C++ would be greatly appreciated!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English Masab 2025-02-19 11:41:24 12 Tiny change: 'dering is :\n\n- Ver' -> 'dering is [1, 2, 0, 3]:\n\n- Ver'
en3 English Masab 2025-02-19 11:36:47 77 Tiny change: '3) (2,3)\n\n 0\' -> '3) (2,3)\n 0\'
en2 English Masab 2025-02-19 11:29:42 93
en1 English Masab 2025-02-19 10:57:21 1654 Initial revision (published)