graph - sorting algorithm for the following? -
so, trying solve following problem:
i solve way:
- create graph
g
each vertex represents letter alphabet. - insert directed edge
v1
v2
g
iff there exist 2 words in given sequence suchw1
=prefix v1 suffix1
,w2
=prefix v2 suffix2
,w1
precedesw2
in given sequence. should figure out how make step efficient. believe can done ino(sum on length of each word)
- return true if
g
can sorted topologicaly.
Comments
Post a Comment