Ordering trees and graphs with few cycles by algebraic connectivity