A genetic algorithm is a metaheuristic approach that mimics natural selection and genetic inheritance to find near-optimal or optimal solutions. It operates on a set of chromosomes that undergo selection, crossover, and mutation to refine underperforming chromosomes and retain those exhibiting better performance. The fitness of the chromosomes serves as a measure of their effectiveness. This algorithm has widespread applications in engineering, computer science, and finance, where it tackles optimization problems. The article demonstrates the principles of the genetic algorithm through a 2D obstacle avoidance problem, focusing on its core operators, i.e., selection, crossover, and mutation. The simulation involves a moving car that travels horizontally while avoiding obstacles that move vertically, where the fitness is defined as the normalized distance traveled by the car before collision. The algorithm iteratively generates new sets of chromosomes through the fundamental operators until it arrives at an optimal or near-optimal solution.