In complex environments, path planning for mobile robots faces challenges such as insensitivity to the environment, low efficiency, and poor path quality with the rapidly-exploring random tree (RRT) algorithm. We propose a novel algorithm, the complex environments rapidly-exploring random tree (CERRT), to address these issues. The CERRT algorithm builds upon the RRT approach and incorporates two key components: a pre-allocated extension node method and a vertex death mechanism. These enhancements aim to improve vertex utilization and overcome the problem of becoming trapped in concave regions, a limitation of traditional algorithms. Additionally, the CERRT algorithm integrates environment awareness at collision points, enabling rapid identification and navigation through narrow passages using local simple sampling techniques. We also introduce the bidirectional shrinking optimization strategy (BSOS) based on the pruning optimization strategy (POS) to further enhance the quality of path solutions. Extensive simulations demonstrate that the CERRT algorithm outperforms the RRT and RRV algorithms in various complex environments, such as mazes and narrow passages. It exhibits shorter running times and generates higher-quality paths, making it a promising approach for mobile robot path planning in challenging environments.