A general recursive form for graph traversals and its transformation