Light trapping has been developed to effectively enhance the efficiency of the thin film solar cell by extending the pathlength for light interacting with the active materials. Searching for optimal light trapping design requires a delicate balance among all the competing physical processes, including light refraction, reflection, and absorption. The existing design methods mainly depend on engineers' intuition to predefine the topology of the light-trapping structure. However, these methods are not capable of handling the topological variation in reaching the optimal design. In this work, a systematic approach based on Genetic Algorithm is introduced to design the scattering pattern for effective light trapping. Inspired by natural evolution, this method can gradually improve the performance of light trapping structure through iterative procedures, producing the most favorable structure with minimized reflection and substantial enhancement in light absorption. Both slot waveguide based solar cell and a more realistic organic solar with a scattering layer consisting of nano-scale patterned front layer is optimized to maximize absorption by strongly coupling incident sun light into the localized photonic modes supported by the multilayer system. Rigorous coupled wave analysis (RCWA) is implemented to evaluate the absorbance. The optimized slot waveguide cell achieves a broadband absorption efficiency of 48.1% and more than 3-fold increase over the Yablonovitch limit and the optimized realistic organic cell exhibits nearly 50% average absorbance over the solar spectrum with short circuit current density five times larger than the control case using planar ITO layer.