lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> I'm storing the adjacency matrix of a directed graph F as a full array
> of sparse arrays: if F[a][b] is not nil, the edge from a to b exists.
> I want to program an algorithm from "Combinatorial Algorithms" which
> starts:
> 1. Let a be any node in the graph. -- easy, a=1 will do.
> 2. Let b be any neighbour of a.    -- easy, b=#F[a]. b==0 means a is isolated.
> 
> Think about it.  How else can you do it?

If you have sparse arrays then it's probably better to use adjacency lists:

w = true -- or any weight
G = {a = {b = w}}

1. Any node in the graph: a = next(G)
2. Any neighbor of a: b = next(G[a])

Cheers,
Luis

-- 
Computers are useless. They can only give you answers.
                -- Pablo Picasso

-- 
Luis Carvalho (Kozure)
lua -e 'print((("lexcarvalho@NO.gmail.SPAM.com"):gsub("(%u+%.)","")))'