Efficient and near-optimal algorithms for sampling connected subgraphs