Theory and Algorithms on the Median Graph: application to Graph-Based Classification and Clustering