This paper is devoted to a systematic study of a class of binary trees encoding the structure of rational numbers both from arithmetic and dynamical point of view. The paper is divided into three parts. The first one is mainly expository and consists in a critical review of rather standard topics such as Stern-Brocot and Farey trees and their connections with continued fraction expansion and the question mark function. In the second part we introduce two classes of (invertible and non-invertible) one-dimensional maps which can be used to generate the binary trees in different ways and study their ergodic properties. This also leads us to study, in the third part, some random processes (Markov chains and martingales) which arise in a natural way from the action of the transfer operators associated to the non-invertible maps.