Learning Small Trees and Graphs that Generalize