algorithm - How to visit vertices in undirected graph -


what proper algorithms visit vertices of undirected graph, arbitrary position? example, given following graph 7 vertices, starting #6:

enter image description here

there many possible sequences: 67645321, 676421235, 6453212467, ...

how iterate vertices shortest path (the first one)? thanks.

follow comment above,

1-2-3   | |   4-5   |   6-7 

sort node value, smaller value go first, results:

6-+-4-+-2-+-1   `-7 `-5 `-3 

transverse tree:

6-4-2-1-2-3-2-4-5-4-6-7 

some more optimization can made, e.g. each node keep 'depth' or weight of each 'child', transverse shallow child / light child first.

6-+-(5)-4-+-(3)-2-+-(1)-1   `-(1)-7 `-(1)-5 `-(1)-3 

thus transverse below:

6-7-6-4-5-4-2-1-2-3 

may have more methods optimize, luck!


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -