bridge edge algorithm implementation