1 Introduction

Recently, the modified theories of gravity have attracted the attention of many researchers in theoretical and observational cosmology and astrophysics. One of the most active research directions is the exploration of many astrophysical problems in a modified f(R) metric theory of gravity. It is most reliable to consider this theory due to its simplicity as regards the derivation as it is obtained by taking a function f(R) of the Ricci scalar, R, for the action as in the Einstein–Hilbert gravitational action. All the modifications of general relativity (GR) explore the problem of dark energy in a more scientific way [1,2,3]. Some major modifications of GR are f(R) gravity [2], \(f(R,\mathcal {T})\) gravity (\(\mathcal {T}\) is the trace of the energy-momentum tensor \(\mathcal {T}_{\alpha \beta }\)) [4], \(f(R,\mathcal {T},\mathcal {Q})\) gravity (where \(\mathcal {Q}=R_{\alpha \beta }T^{\alpha \beta }\)) [5], Gauss–Bonnet gravity [6], teleparallel modified theories [7, 8], and scalar–tensor theories [9]. It has been pointed out by many researchers [3,4,5,6,7,8] that the f(R) theory confirms that when major interactions are unified this leads to actions which involve curvature invariants of nonlinear order.

During the last decades many renowned researchers have investigated the gravitational collapse in modified theories. It has been shown that as one goes beyond the general relativity, one has more chances of admitting an uncovered singularity. A lot of work has been done in GR as regards the gravitational collapse [10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]. The nonlinear electrodynamics static black holes (BH) solutions have been formulated within the frame work of f(R) [25]. In this connection Borisov et al. [26] have investigated the spherical gravitational collapse in f(R) gravity by performing one-dimensional numerical simulations. In this study, the nonlinear self-interaction coupling of the scalar field has been included in the dynamical equations and a relation scheme has been used to follow the gravitationally contracting solutions. During the scalar-field collapse in f(R) gravity, the density increases rapidly near the virial radius, which may provide an observable test of gravity. Schmidt [27] has used large scale simulations for spherical collapse in f(R) gravity to estimate the halo mass function. Capozziello et al. [28] have investigated the hydrostatic equilibrium and stellar structure in f(R) gravity.

Cembranos et al. [29], have explored the gravitational collapse of matter with uniform density in f(R) gravity. This analysis provides information as regards the structure formation in the early universe. It has been remarked that, for some particular models of f(R) gravity, the gravitational collapse process would help to constrain the models that exhibit the late-time cosmological acceleration. The time of collapse in this frame work has been observed to be much smaller as compared to the age of the universe while it is much longer to form the matter clustering. All of the previous investigations of gravitational collapse in f(R) gravity imply that gravity is a highly attractive force—this is in the agreement with the observed consequences of f(R) gravity. It is an admitted fact that a scalar force would reduce the time for gravitational collapse because of its attractive behavior. Ghosh and Maharaj [30] have explored the exact models of null dust collapse in metric f(R) theory with the constant scalar curvature condition. Further, in this situation the null dust collapse leads to the formation of naked singularities, hence violating the cosmic censorship conjecture (CCC) in f(R) gravity. Goswami et al. [31] have proved that a gravitational collapse of heat conducting, shearing and anisotropic fluid in f(R) seems to be unstable with respect to matter perturbations. There exist no apparent horizons and hence there occur naked singularities. It is important to note that investigating CCC in modified gravity may be more complicated than in GR. It has been well established that inhomogeneity is closely related to spacetime shear and Weyl curvature of the collapsing star, which produces the naked singularities.

The Oppenheimer–Snyder–Datt model [10, 32], which is a widely acceptable model for BH formation via dynamical collapse is no longer a viable model in modified f(R) gravity. Hence in order to establish the existence of BH solutions via stellar collapse in modified f(R) theories, we have to find some new physically reasonable solutions in modified f(R) gravity that may predict BHs. Hwang et al. [33] have investigated the collapse of a charged BH in f(R) gravity using the double null formalism and constant scalar curvature assumption. In such charged BH solutions there appears a new type of singularity due to higher curvature corrections, the so-called f(R) induced singularity. Pun et al. [34] have confirmed the existence of a Schwarzschild-like BH solution in f(R) gravity. The modified f(R) theories of gravity provide toy models for the existence and stability of neutron stars [35]. The stars which satisfy the baro-tropic equation of state \((\rho =\omega p)\) in f(R) gravity, when they undergo gravitational collapse, have an end state of the collapse that would be a naked singularity violating CCC [36].

Sharif and Nasir [37] have discussed the stability of expansion-free axially symmetric fluids in f(R) gravity. The gravitating source preserves its axial symmetry due to the f(R) extra degree of freedom. Also, the axially symmetric solutions have been formulated in f(R) gravity by using the Newman–Janis method [38]. The rotating black string solutions have been investigated in f(R)-Maxwell gravity [39] using the constant scalar curvature assumption. Sharif et al. [40,41,42,43,44] have studied the dynamical stabilities of many gravitating stellar systems in f(R) theories with the general form of f(R) models. The instability and anti-evaporation of Reissner–Nordstr\(\ddot{\mathrm{{o}}}\)m BHs have been explored in the modified f(R) gravity [45]. The inhomogeneous dust as well perfect fluid collapse with the geodesic flow condition in 4D have been explored in [46, 47]. It has been remarked that f(R) with constant scalar curvature would appear as an alternative to the cosmological constant.

Recent advancements in string theory and other field theories indicate that gravity is a higher-dimensional interaction. It would be interesting to determine an analytic model of stellar contraction and singularity formation in more than 4D. The most general forms of a Vaidya solution for a null fluid in Lovelock theory of gravity have been explored by many authors [48,49,50] and they arrived at the conclusion that the uncovered singularities are feasible for an odd dimension for several values of the parameters and, due to the gravitational collapse, a BH is formed for any value of the parameters. Banerjee et al. [51] studied the uncovered singularities in higher-dimensional gravitational collapse and concluded that there is a great chance of an uncovered singularity. Feinstein [52] investigated the formation of a black string for gravitational collapse in a higher-dimensional vacuum. In this paper, the work done by Sharif and Kausar [47] is extended for \(n+2\)-dimensional spacetime. The scheme of the paper is as follows. In Sect. 2, the field equations are given. Section 3 is devoted to solutions of the field equations. In Sect. 4, trapped surfaces and apparent horizons are discussed in detail. Finally, the results are summarized in Sect. 5.

2 LTB model and equations of motion in f(R) gravity

For the interior region we take the \(n+2\)-dimensional non-static spherically symmetric LTB metric given by

$$\begin{aligned} \mathrm{d}s^{2}_{-}= \mathrm{d}t^{2}-A^{2}\mathrm{d}r^{2}-Y^{2}\mathrm{d}\Omega ^{2}, \end{aligned}$$
(2.1)

where \(A=A(r,t)\) and \(Y=Y(r,t)\). We have

$$\begin{aligned} \mathrm{d}\Omega ^{2}= & {} \sum ^{n}_{k=1}\left[ \prod ^{k-1}_{l=1}\mathrm{sin}^{2} \theta _{l}\right] \mathrm{d}\theta ^{2}_{k} =\mathrm{d}\theta _{1}^{2}+\mathrm{sin}^{2}\theta _{1}\mathrm{d}\theta _{2}^{2}\nonumber \\&+\,\mathrm{sin}^{2}\theta _{1}\mathrm{sin}^{2} \theta _{2}\mathrm{d}\theta _{3}^{2} \nonumber \\&+\cdots +\mathrm{sin}^{2}\theta _{1}\mathrm{sin}^{2}\theta _{2}\mathrm{sin}^{2}\theta _{3}\cdots \mathrm{sin}^{2} \theta _{n-1}\mathrm{d}\theta _{n}^{2}. \end{aligned}$$
(2.2)

In f(R) gravity the equations of motion are [1,2,3]

$$\begin{aligned}&F(R)R_{\pi \chi }-\frac{1}{2}f(R)g_{\pi \chi }-\nabla _{\pi }\nabla {\chi }F(R) +g_{\pi \chi }\nabla ^{\sigma }\nabla _{\sigma }F(R)\nonumber \\&\quad =\kappa T_{\pi \chi }. \end{aligned}$$
(2.3)

Here \(F(R)=\mathrm{d}f(R)/\mathrm{d}R\), \(\nabla _{\pi }\) is the covariant derivative, \(T_{\pi \chi }\) is the standard energy-momentum tensor and \(\kappa \) is the coupling constant. The perfect fluid source is

$$\begin{aligned} T_{\pi \chi }=(\rho +p)u_{\pi }u_{\chi }-pg_{\pi \chi }, \end{aligned}$$
(2.4)

where \(\rho =\rho (r,t)\) is the fluid matter density, p is the fluid pressure and \(u_{\pi }\) is the \(n+2\)-dimensional velocity vector defined by \(u_{\pi }=\delta ^{0}_{\pi }\). For the metric (2.1), we get the following set of independent partial differential equations:

$$\begin{aligned}&-\frac{\ddot{A}}{A}-n\frac{\ddot{Y}}{Y}=\frac{1}{F} \left[ \kappa \rho +\frac{f}{2}\right] -\bigg [-\frac{F^{\prime \prime }}{A^{2}} +\frac{\dot{A}}{A}\dot{F}+\frac{A^{\prime }}{A^{3}}F^{\prime }\nonumber \\&\quad +n\frac{\dot{Y}}{Y}\dot{F}-n\frac{Y^{\prime }}{A^{2}Y}F^{\prime }\bigg ], \end{aligned}$$
(2.5)
$$\begin{aligned}&-\frac{\ddot{A}}{A}-n\frac{\dot{A}}{A}\frac{\dot{Y}}{Y} +\frac{n}{A^{2}}\bigg [\frac{Y^{\prime \prime }}{Y}-\frac{A^{\prime } Y^{\prime }}{AY}\bigg ]\nonumber \\&\quad =\frac{1}{F}\bigg [\frac{f}{2}-\kappa {p}-A^{2}\bigg (\ddot{F} +n\frac{\dot{Y}}{Y}\dot{F}-n\frac{Y^{\prime }}{A^{2}Y}F^{\prime }\bigg )\bigg ],\end{aligned}$$
(2.6)
$$\begin{aligned}&-\frac{\ddot{Y}}{Y}-(n-1)\bigg (\frac{\dot{Y}}{Y}\bigg )^{2}-\frac{\dot{A}\dot{Y}}{AY} \nonumber \\&\qquad +\frac{1}{A^{2}}\bigg [\frac{Y^{\prime \prime }}{Y}+(n-1)\bigg (\frac{Y^{\prime }}{Y}\bigg )^{2}\nonumber \\&\qquad -\frac{A^{\prime }Y^{\prime }}{AY}-(n-1)\bigg (\frac{A}{Y}\bigg )^{2}\bigg ] \nonumber \\&\quad =\frac{1}{F}\bigg [\frac{f}{2}-\kappa {p}-\bigg (\ddot{F}-\frac{F^{\prime \prime }}{A^{2}} +\frac{\dot{A}}{A}\dot{F}+\frac{A^{\prime }}{A^{3}}F^{\prime }\nonumber \\&\qquad +(n-1)\frac{\dot{Y}}{Y}\dot{F}-(n-1)\frac{Y^{\prime }F^{\prime }}{A^{2}Y}\bigg )\bigg ], \end{aligned}$$
(2.7)
$$\begin{aligned}&-n\frac{\dot{Y^{\prime }}}{Y}+n\frac{\dot{AY^{\prime }}}{AY} =\frac{1}{F}\bigg [\dot{F}^{\prime }-\frac{\dot{A}}{A}F^{\prime }\bigg ]. \end{aligned}$$
(2.8)

Here \(\cdot \) and \('\) are for the partial derivatives with respect to t and r, respectively.

Using the scalar perturbation constraints, Cooney et al. [53] have explored the formation of compact objects like a neutron star in f(R) gravity. The Schwarzschild metric cosmological constant has been considered in the external region, which has been matched smoothly with the interior fluid solution using Darmois junction conditions in a very similar way to GR. According to the authors of [54, 55] the Schwarzschild solution is the most suitable solution for the exterior geometry of the star. In the same way in f(R) gravity many researchers [40,41,42,43,44, 56, 57] have examined the matching conditions for gravitational collapse.

For the exterior region, we consider the \(n+2\)-dimensional Schwarzschild metric

$$\begin{aligned} \mathrm{d}s^{2}_{+}=1-\frac{2M}{R}\mathrm{d}t^{2}-\frac{1}{1-\frac{2M}{R}} \mathrm{d}r^{2}-R^{2}\mathrm{d}\Omega ^{2}. \end{aligned}$$
(2.9)

The matching conditions require that:

1. The first fundamental form of the metrics must be continuous over \(\Sigma \), i.e.,

$$\begin{aligned} (\mathrm{d}s^{2}_{+})_{\sum }=(\mathrm{d}s^{2}_{-})_{\sum }=(\mathrm{d}s^{2})_{\sum }. \end{aligned}$$
(2.10)

2. Also, the extrinsic curvature must be continuous over \(\Sigma \) i.e.,

$$\begin{aligned}{}[K_{cd}]=K^{+}_{cd}-K^{-}_{cd}=0,\quad (i,j=0,2,3\ldots n+1), \end{aligned}$$
(2.11)

where \(K_{cd}\) is the extrinsic curvature tensor defined as

$$\begin{aligned}&K^{\pm }_{cd}=-n^{\pm }_{\omega }\left( \frac{\partial ^{2}x^{\omega }_{\pm }}{\partial \xi ^{c}\partial \xi ^{d}} +{\Gamma _{\gamma \delta }^{\omega }}\frac{{\partial }x^{\gamma }_{\pm }{\partial } x^{\delta }_{\pm }}{{\partial }\xi ^{c}{\partial }\xi ^{d}}\right) ,\nonumber \\&\quad (\omega ,\gamma ,\delta =0,1,2,3\ldots n+1). \end{aligned}$$
(2.12)

Here \(n^{\pm }_{\omega }\), \(x^{\omega }_{\pm }\) and \(\xi ^{c}\) denotes the outward coordinates on \(V^{\pm }\), \(\Sigma \), respectively. The equations of hypersurfaces for the inner and outer metrics are given by

$$\begin{aligned}&h_{-}(r,t) =r-r_{\Sigma }=0 , \end{aligned}$$
(2.13)
$$\begin{aligned}&h_{+}(R,T) =R-R_{\Sigma }(T)=0, \end{aligned}$$
(2.14)

where \(r_{\Sigma }\) is a constant. Using Eq. (2.13) in Eq. (2.1), the interior metric on the hypersurface \(\Sigma \) takes the following form:

$$\begin{aligned} \mathrm{d}s_{-}^{2}=\mathrm{d}t^{2}-Y^{2}\mathrm{d}\Omega ^{2}. \end{aligned}$$
(2.15)

Also, plugging Eq. (2.14) into Eq. (2.9), we get

$$\begin{aligned} \mathrm{d}s^{2}_{+}=\left( \left( 1-\frac{2M}{R}\right) \!-\!\frac{1}{\left( 1-\frac{2M}{R}\right) }\left( \frac{\mathrm{d}R_{\Sigma }}{\mathrm{d}T}\right) ^{2}\right) \mathrm{d}T^{2}-R^{2}\mathrm{d}\Omega ^{2}. \end{aligned}$$
(2.16)

For T a timelike coordinate, we assume

$$\begin{aligned} \left( \left( 1-\frac{2M}{R}\right) -\frac{1}{\left( 1 -\frac{2M}{R}\right) }\left( \frac{\mathrm{d}R_{\Sigma }}{\mathrm{d}T}\right) ^{2}\right) >0. \end{aligned}$$
(2.17)

Now from the junction condition equation (2.10), we get

$$\begin{aligned} R_{\Sigma }=Y(r_{\Sigma },T), \end{aligned}$$
(2.18)
$$\begin{aligned} \left[ Z(R)-\frac{1}{Z(R)}\left( \frac{\mathrm{d}R_{\Sigma }}{\mathrm{d}T}\right) ^{2}\right] ^\frac{1}{2}\mathrm{d}T=\mathrm{d}t, \end{aligned}$$
(2.19)

where \(Z(R)=1-\frac{2M}{R}\). The possible components of \(K_{cd}^{\pm }\) are

$$\begin{aligned} K_{00}^{-}= & {} 0, \end{aligned}$$
(2.20)
$$\begin{aligned} K_{22}^{-}= & {} \csc ^{2}\theta _{1}K^{-}_{33}=\csc ^{2}\theta _{1}\csc ^{2} \theta _{2}K^{-}_{44} \nonumber \\= & {} \cdots =\csc ^{2}\theta _{1}\csc ^{2}\theta _{2}\cdots \csc ^{2} \theta _{n}K^{-}_{n+1n+1}=\bigg (\frac{YY^{\prime }}{A}\bigg )_{\Sigma },\end{aligned}$$
(2.21)
$$\begin{aligned} K_{00}^{+}= & {} \bigg [\dot{R}\ddot{T}-\dot{T}\ddot{R}+\frac{3M\dot{R}^{2} \dot{T}}{R(R-2M)}-\frac{\dot{T}^{3}M(R-2M)}{R^{3}}\bigg ]_{\Sigma },\end{aligned}$$
(2.22)
$$\begin{aligned} K^{+}_{22}= & {} \csc ^{2}\theta _{1}K^{+}_{33}=\csc ^{2}\theta _{1}\csc ^{2} \theta _{2}K^{+}_{44} \nonumber \\= & {} \cdots =\csc ^{2}\theta _{1}\csc ^{2}\theta _{2}\cdots \csc ^{2}\theta _{n} K^{+}_{n+1n+1}=(\dot{T}(R-2M))_{\Sigma }.\nonumber \\ \end{aligned}$$
(2.23)

Now from the continuity of the extrinsic curvature (2.11), it follows that

$$\begin{aligned} K^{+}_{00}=0,\quad K_{22}^{+}= K_{22}^{-}. \end{aligned}$$
(2.24)

Now using Eqs. (2.202.24) along with (2.18) and (2.19), the junction takes the form

$$\begin{aligned} (A\dot{Y^{\prime }}-\dot{A}Y^{\prime })_{\Sigma }=0, \end{aligned}$$
(2.25)
$$\begin{aligned} M=\frac{n-1}{2}Y^{n-1}\left( 1-\dot{Y}^{2}-\frac{Y'^2}{A^2}\right) _{\Sigma }. \end{aligned}$$
(2.26)

Equations (2.18), (2.19), (2.25) and (2.26) are the required conditions for the matching of two regions.

3 Solution

We need the explicit value of A, for the solution of the set of fields Eqs. (2.5)–(2.9). It follows from Eq. (2.9) that

$$\begin{aligned} A=\int \frac{n\dot{Y^{\prime }}F+\dot{F^{\prime }}Y}{nY^{\prime }F+F^{\prime }Y}\mathrm{d}t. \end{aligned}$$
(3.1)

To solve the above equation, we assume \(R=R_{0}\), and \(F(R_{0})=constant\) and this assumption provides us with \(p=p_0\) and \(\rho =\rho _0\); here the quantities with subscript 0 are constant quantities. In modified gravitation theories the stability of models is tested through the Dolgov and Kawasaki [58] stability criterion,

$$\begin{aligned} F(R)=f_R(R)>0,\quad f_{RR}(R)>0,\quad R \ge R_{0}. \end{aligned}$$
(3.2)

Using the above assumptions, Eqs. (2.5)–(2.9) yield

$$\begin{aligned}&-\frac{\ddot{A}}{A}-n\frac{\ddot{Y}}{Y}=\frac{1}{F} \left[ \kappa \rho +\frac{f}{2}\right] ,\end{aligned}$$
(3.3)
$$\begin{aligned}&-\frac{\ddot{A}}{A}-n\frac{\dot{A}}{A} \frac{\dot{Y}}{Y}+\frac{n}{A^{2}}\bigg [\frac{Y^{\prime \prime }}{Y}-\frac{A^{\prime }Y^{\prime }}{AY}=\frac{1}{F}\bigg [\frac{f}{2} -\kappa {p}\bigg ],\end{aligned}$$
(3.4)
$$\begin{aligned}&-\frac{\ddot{Y}}{Y}-(n-1)\bigg (\frac{\dot{Y}}{Y}\bigg )^{2} -\frac{\dot{A}\dot{Y}}{AY}+\frac{1}{A^{2}}\bigg [\frac{Y^{\prime \prime }}{Y}\nonumber \\&\qquad +(n-1)\bigg (\frac{Y^{\prime }}{Y}\bigg )^{2}-\frac{A^{\prime }Y^{\prime }}{AY}-(n-1) \bigg (\frac{A}{Y}\bigg )^{2}\bigg ] \nonumber \\&\quad =\frac{1}{F}\bigg [\frac{f}{2}-\kappa {p}\bigg ],\end{aligned}$$
(3.5)
$$\begin{aligned}&-n\frac{\dot{Y^{\prime }}}{Y}+n\frac{\dot{AY^{\prime }}}{ AY}=0. \end{aligned}$$
(3.6)

Now from Eq. (3.6), it follows that

$$\begin{aligned} A(r,t)=\frac{Y^{\prime }(r,t)}{W(r)}, \end{aligned}$$
(3.7)

where \(W=W(r)\). Using Eq. (3.8) in Eqs. (3.3)–(3.6), it follows that

$$\begin{aligned}&2\frac{\ddot{Y}}{Y}+(n-1)\bigg (\frac{\dot{Y}}{Y}\bigg )^{2} +(n-1)\bigg (\frac{1-W^{2}}{Y^{2}}\bigg )\nonumber \\&=-\frac{1}{F(R_{0})}\bigg [\frac{8\pi }{n}((n-1)p_{0} -\rho _{0})-\frac{f(R_{0})}{2}\bigg ]. \end{aligned}$$
(3.8)

The above equation yields

$$\begin{aligned} (\dot{Y})^{2}= & {} W^{2}-1+2\frac{m(r)}{Y^{n-1}}-\frac{Y^{2}}{(n+1)F(R_{0})}\nonumber \\&\times \,\left[ \frac{8\pi }{n}((n-1) p_{0}-\rho _{0})-\frac{f(R_{0})}{2}\right] , \end{aligned}$$
(3.9)

here \(m=m(r)\) and its value is given by

$$\begin{aligned} m^{\prime }=\frac{8\pi }{nF(R_{0})}((n-1)p_{0}+\rho _{0})Y^{\prime }Y^{n}. \end{aligned}$$
(3.10)

Also, the above equation leads to

$$\begin{aligned} m(r)=\frac{8\pi }{nF(R_{0})}(p_{0}(n-1)+\rho _{0})\int (Y'Y^{n} )\mathrm{d}r+c(t), \end{aligned}$$
(3.11)

where c(t) is an arbitrary function of t. The function m(r) must be positive. Using the second junction condition from Eqs. (3.5) and (3.9), we get

$$\begin{aligned} M= & {} (n-1)m(r)-\frac{(n-1)Y^{n+1}}{2(n+1)F(R_{0})}\nonumber \\&\times \,\left[ \frac{8\pi }{n}((n-1)p_{0} -\rho _{0})-\frac{f(R_{0})}{2}\right] . \end{aligned}$$
(3.12)

Now using the mass function [11], the total energy M(rt) for the interior spacetime is defined as

$$\begin{aligned} M(r,t)=\frac{(n-1)Y^{n-1}}{2}[1+g^{\pi \chi }Y_{,\pi }Y_{,\chi }]. \end{aligned}$$
(3.13)

Using Eq. (3.9), the mass function becomes

$$\begin{aligned} M(r,t)= & {} (n-1)m(r)-\frac{(n-1)Y^{n+1}}{2(n+1)F(R_{0})}\nonumber \\&\times \,\left[ \frac{8\pi }{n}((n-1)p_{0}-\rho _{0})-\frac{f(R_{0})}{2}\right] , \end{aligned}$$
(3.14)

Now we assume that

$$\begin{aligned} \frac{1}{F(R_{0})}\left[ \frac{8\pi }{n}((n-1)p_{0}-\rho _{0})-\frac{f(R_{0})}{2}\right] >0, \end{aligned}$$
(3.15)

and the condition \(W(r)=1\) to find the solution, so Eq. (3.9) implies that

$$\begin{aligned} Y= & {} \bigg (\frac{2(n+1)mF(R_{0})}{\frac{8\pi }{n}((n-1)p_{0}-\rho _{0}) -\frac{1}{2}f(R_{0})}\bigg )^\frac{1}{n+1}\sinh ^{\frac{2}{n+1}} \alpha ({r,t}),\end{aligned}$$
(3.16)
$$\begin{aligned} A= & {} \bigg (\frac{2(n+1)mF(R_{0})}{\frac{8\pi }{n}((n-1)p_{0}-\rho _{0}) -\frac{1}{2}f(R_{0})}\bigg )^\frac{1}{n+1}\bigg [\frac{m^{\prime }}{(n+1)m}\sinh {\alpha (r,t)} \nonumber \\&+t^{\prime }_{s}(r)\sqrt{\frac{\frac{8\pi }{n}((n-1)p_{0} -\rho _{0})-\frac{1}{2}f(R_{0})}{(n+1)F(R_{0})}}\cosh {\alpha (r,t)}\bigg ] \sinh ^{\frac{(1-n)}{(1+n)}}{\alpha (r,t)},\nonumber \\ \end{aligned}$$
(3.17)

where

$$\begin{aligned} \alpha ({r,t})=\sqrt{\frac{(n+1)\bigg (\frac{8\pi }{n}((n-1)p_{0}-\rho _{0}) -\frac{1}{2}f(R_{0})\bigg )}{4F(R_{0})}}[t_{s}(r)-t]. \end{aligned}$$
(3.18)

We would like to mention that in the limit \(f(R_{0})\rightarrow \frac{8\pi (p_{0}-\rho _{0})}{n}\), we have the Tolman–Bondi solution [59]

$$\begin{aligned} Y= & {} \left[ \frac{(n+1)^{2}m(r)}{2}(t_{s}-t)^{2}\right] ^{\frac{1}{n+1}}, \end{aligned}$$
(3.19)
$$\begin{aligned} A= & {} \frac{m^{\prime }(t_{s}-t)+2mt^{\prime }_{s}}{[2(n+1)^{n-1}m^{n}(t_{s}-t)^{n-1}]^\frac{1}{n+1}}. \end{aligned}$$
(3.20)

From Eqs. (3.2) and (3.15), we get \(F(R_0)>0\) and \(f(R_0)<\frac{16\pi }{n}[(n-1)p_0-\rho _0]\). The Dolgov and Kawasaki [58] stability criterion does not restrict the sign of \(f(R_0)\). Therefore, for \({\rho _0}>0\), we must have \((n-1)p_0<\rho _0\); it holds for all \(n\ge 1\), and finally we get \(f(R_0) <0\). Hence these are the viability conditions for f(R) gravity that must hold throughout the discussion.

4 Apparent horizons

For spacetime (2.1) the boundary of a trapped n-sphere is given by

$$\begin{aligned} g^{\pi \chi }Y,_{\pi }Y,_{\chi }=\frac{A^2\dot{Y}^{2}-Y'}{A^2}=0. \end{aligned}$$
(4.1)

Using Eq. (3.9), the above equation yields

$$\begin{aligned}&\frac{1}{F(R_{0})}\left[ \frac{8\pi }{n}((n-1)p_{0}-\rho _{0})-\frac{f(R_{0})}{2}\right] \nonumber \\&\quad \times Y^{n+1}-(n+1)Y^{n-1}+2(n+1)m=0. \end{aligned}$$
(4.2)

The values of Y give the boundaries of trapped surfaces which are the apparent horizons. For \(f(R_{0})=2(\frac{8\pi }{n}((n-1)p_{0}-\rho _{0})))\), one gets \(Y=(2m)^{\frac{1}{n-1}}\), which is the Schwarzschild n-radius. It gives a de Sitter horizon, when \(m=0\), i.e.,

$$\begin{aligned} Y=\sqrt{\frac{(n+1)F(R_{0})}{\frac{8\pi }{n}((n-1)p_{0}-\rho _{0}) -\frac{f(R_{0})}{2}}}. \end{aligned}$$
(4.3)

The approximate solution of Eq. (4.2) up to first order in m and \(\frac{1}{F(R_{0})}[\frac{8\pi }{n}((n-1)p_{0}-\rho _{0})-\frac{f(R_{0})}{2})]\), respectively, are given by

$$\begin{aligned}&(Y)_{ch}=\bigg (\frac{(n+1)F(R_{0})}{\frac{8\pi }{n}((n-1)p_{0}-\rho _{0}) -\frac{f(R_{0})}{2}}\bigg )^{\frac{1}{2}}\nonumber \\&\quad -2\bigg (\bigg (\frac{nF(R_{0})}{8\pi ((n-1)p_{0} -\rho _{0})-\frac{1}{2}f(R_{0})}\bigg ) \nonumber \\&\quad \times \bigg (\bigg ((n+1)\frac{8\pi ((n-1)p_{0}-\rho _{0})-\frac{1}{2}f(R_{0})}{nF(R_{0})}\bigg )\bigg )^{\frac{n}{2}}\nonumber \\&\quad \times \bigg (\frac{8\pi ((n-1)p_{0}-\rho _{0})-\frac{1}{2}f(R_{0})}{n(n-1)(n+1) F(R_{0})}\bigg )^{\frac{n-2}{2}}\bigg )m\ldots ,\end{aligned}$$
(4.4)
$$\begin{aligned}&(Y)_{bh}=(2m)^{\frac{1}{n-1}}+\frac{1}{F(R_{0})}\nonumber \\&\quad \times \bigg (\frac{8\pi ((n-1)p_{0} -\rho _{0})-\frac{1}{2}f(R_{0})}{n(n-1) (n+1)}\bigg )(2m)^{\frac{3}{n-1}}f(R_{0})\ldots .\nonumber \\ \end{aligned}$$
(4.5)

\((Y)_{ch}\) and \((Y)_{bh}\) are called the cosmological and black hole, respectively. The existence of \((Y)_{ch}\) is mainly due to the appearance of the f(R) term. Now from Eqs. (3.18) and (4.2), the time for the trapped surfaces’ formation is

$$\begin{aligned} t_{n}= & {} t_{s}-\sqrt{\frac{4F(R_{0})}{(n+1)\left[ \frac{8\pi }{n} ((n-1)p_{0}-\rho _{0})-\frac{f(R_{0})}{2}\right] }}\nonumber \\&\times \,\sinh ^{-1} \left[ \frac{(Y_{n})^{n-1}}{2m(r)}-1\right] ^\frac{1}{2},\quad n=1,2. \end{aligned}$$
(4.6)

In the limiting case when \(f(R_{0})\rightarrow 2\big (\frac{8\pi }{n}(\rho _{0}-(n-1)p_{0})\big )\), the result coincides with the Tolman–Bondi solution [59],

$$\begin{aligned} t_{n}=t_{s}-\frac{(2^{n}m)^{\frac{1}{n-1}}}{n+1}. \end{aligned}$$
(4.7)

It is clear from Eq. (4.6) that the formation of trapped surfaces takes less time as compared to the time of formation of a singularity, \(t=t_{s}\). This implies that horizons form earlier than the singularity, hence the singularity is covered by the event horizons, and the end state of gravitational collapse is a BH. The present solutions in f(R) are in agreement with Oppenheimer–Snyder–Datt models. Hence the end state of gravitational collapse is a BH. From Eq. (4.7) it is to be noted that the time for forming trapped surfaces in higher-dimensional Tolman–Bondi spacetime is a special case of our present investigation. Further, the \(f(R_0)\) term affects the time lag between the formation of trapped surfaces and the singularity. The Misner–Sharp mass [11] has been modified by \(f(R_0)\). Also, the exterior trapped surface, the so-called cosmological horizon is due to the presence of the \(f(R_0)\) term. We explored the physical aspects of the solutions and found a suitable counterterm in the analytic solutions which avoids the occurrence of a naked singularity during gravitational collapse.

The Dolgov and Kawasaki [58] stability criterion \(F(R)=f_R(R)>0\), \(R{\ge }R_{0}\), explains that f(R) theory must avoid a ghost state, while the second condition, \(f_{RR}(R)>0,\ R{\ge }R_{0}\) is introduced to avoid a negative mass squared of a scalar-field degree of freedom. Hence the present solutions are ghost free and free of any exotic matter instability caused by the external perturbation [41]. This means the final state of gravitational collapse in the present case is not a two phase transition. In other words one may not have any condition to convert a BH into naked singularity. This shows that, in f(R) gravity, the instability of a gravitating system decreases rapidly and the system tends to a stable state naturally. This is the important consequence of what we expect as the f(R) theory modifies the interaction of gravity by the inclusion of a new scalar field. We have investigated that \(f(R_0)\) plays a dominant role in trapping the collapsing fields and contributes to the black hole formation. Due to the repulsive nature of the scalar force, the \(f(R_0)\) term slows down the collapse rate.

5 Conclusion

It is particularly interesting to establish the predictions of f(R) theories concerning the gravitational collapse, and particularly the collapse time, for several astrophysical objects. The outcomes of the analysis of gravitational collapse in f(R) theory may provide constraints for the validity of models and be helpful to discard the models which appear to contradict experimental investigations. Here, we have examined the gravitational contraction of an inhomogeneous perfect fluid in f(R) gravity by considering the metric approach. We have assumed an \(n+2\)-dimensional spacetime with an inhomogeneous and isotropic perfect fluid as the gravitating source. The n-dimensional fluid sphere is taken as the interior and Schwarzschild spacetimes as exterior region, respectively. The general conditions for the smooth matching of two regions have been formulated. For the solution of the field equations, the assumption of constant curvature is used, which implies that pressure and density are constants in this case. Two physical apparent horizons, the black hole horizon and the cosmological horizon, have been found. We have shown that trapped surfaces are formed earlier than the singular point of the collapsing sphere, hence a singularity is covered by the black hole horizon. This favors the cosmic censorship conjecture.

From Eq. (3.9), the rate at which fluid sphere collapse occurs is given by

$$\begin{aligned} \ddot{Y}= & {} -\frac{(n-1)m}{Y^{n}}+\frac{Y}{(n+1)F(R_{0})}\nonumber \\&\times \,\left[ \frac{8\pi }{n} ((n-1)p_{0}-\rho _{0})-\frac{f(R_{0})}{2}\right] . \end{aligned}$$
(5.1)

For the collapsing process, the acceleration should be negative, which is possible when

$$\begin{aligned} Y<\left[ -\frac{(n-1)(n+1)mF(R_{0})}{\frac{8\pi }{n}((n-1)p_{0}-\rho _{0}) -\frac{f(R_{0})}{2}}\right] ^{\frac{1}{n+1}}. \end{aligned}$$
(5.2)

It is evident from Eq. (5.1) that the \(f(R_{0})\) term slows down the collapsing process (as mentioned in [26]) when \(\frac{1}{F(R_{0})}(\frac{8\pi }{n}((n-1)p_{0}-\rho _{0})-\frac{f(R_{0})}{2})<{0}\) is satisfied. Further, due to the \(f(R_{0})\) term there exist two physical horizons, namely the black hole horizon and the cosmological horizon. We would like to point out that, for \(n=2\), our results match the results of Sharif and Kausar [47].

As mentioned earlier (in the introduction), there are two types of solutions concerning the gravitational collapse in f(R) gravity: one predicts a naked singularity and the other a BH. In [30, 31, 35], the final state of gravitational collapse in f(R) gravity is a naked singularity, while in [33, 34, 36, 37, 45] a BH has been found as a final outcome of collapse in f(R) gravity. Thus our results favor the investigations of [33, 34, 36, 37, 45] and may be considered as one example of Oppenheimer–Snyder–Datt models in f(R) gravity. The \(f(R_0)\) term slows down the process of gravitational collapse, and this favors the finding of Ref. [26]. Finally, we would like to mention that the results of this paper can be extended in the frame work of other modified theories of gravity, like f(T), f(G), f(RG) and f(RT).