graph match algorithm