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