In this paper, we propose an algorithm that achieves the MAP solution to decode LDPC codes over the binary erasure channel (BEC). This algorithm, denoted as generalized tree-structured expectation propagation (GTEP), extends the idea of our previous work: the TEP decoder. Both proposals borrow from the tree-structured expectation propagation algorithm, which imposes a tree-like approximation over the original graphical model. However, whereas the TEP decoder only considers up to degree two check nodes, the proposed GTEP modifies the graph by eliminating a check node of any degree and merging this information with the remaining graph. The decoder builds a tree graph of relations between the erased variable nodes with respect to some parent variables. The GTEP algorithm upon completion either provides the unique MAP solution or a tree graph in which the number of parent nodes indicates the multiplicity of the MAP solution. This algorithm can be easily described for the BEC, and it can be cast as a generalized peeling decoder. The GTEP decoder can look for checks nodes of minimum degree to be eliminated first, optimizing the complexity of the decoder. Furthermore, this procedure yields an upper bound for the complexity of the MAP decoder. We include an analysis of the computational complexity of this novel decoder to show that it is a function of the erasure value of the channel, the length of the codeword and the ensemble of the code. We illustrate the proposed algorithm with regular codes, which do not present error floors and achieve capacity when the number of ones per column increases.