wrote pseudocode-ish functions for spanning and matching