— We show that for every fixed k, there is a linear time algorithm that decides whether or not a given graph has a vertex set X of order at most k such that G − X is planar (we call this class of graphs k-apex), and if this is the case, computes a drawing of the graph in the plane after deleting at most k vertices. In fact, in this case, we shall determine the minimum value l ≤ k such that after deleting some l vertices, the resulting graph is planar. If this is not the case, then the algorithm gives rise to a minor which is not kapex and is minimal with this property. This answers the question posed by Cabello and Mohar in 2005, and by Kawarabayashi and Reed (STOC’07), respectively. Note that the case k = 0 is the planarity case. Thus our algorithm can be viewed as a generalization of the seminal result by Hopcroft and Tarjan (J. ACM 1974), which determines if a given graph is planar in linear time. Our algorithm can be also compared to the algorithms by Mohar (STOC’96 and ...