I need to write SCC algorithm in standard ML. But I don’t know how.
I have following TYPEs which have to be uesd in the code:
type vertex = int
type edge = int * int
type graph = (vertex * vertex list) list
fun dfs (g: graph) (n: vertex): vertex list =
let
fun helper (todo: vertex list) (visited: vertex list): vertex list =
case todo of
[] => []
| h::t => if (List.exists (fn x => x = h) visited)
then helper t visited
else
let
val adj = case List.find (fn (n, _) => n = h) g of
NONE => raise Fail "incomplete adjacency list"
| SOME (_, adj) => adj
in
h :: (helper (adj @ t) (h::visited))
end
in
helper [n] []
end
The above code has been compiled and run correctly.
I put these in the code because I know in computing SCC dfs is needed.
Does anyone have a solution?
Pseudo code – http://algowiki.net/wiki/index.php/Tarjan's_algorithm.