distance algorithm figure distances similarity set method pattern segments matrix feature graph methods features representation comparison pp algorithms tree