Maximum order of trees and bipartite graphs with a given rank