Pregunta de entrevista de Johnson & Johnson

Graph algorithms such as BFS, DFS, RRT

Respuesta de la entrevista

Anónimo

4 mar 2026

Breadth-First Search (BFS) explores a graph level by level, visiting all neighbors of a node before moving deeper. It uses a queue and guarantees the shortest path in unweighted graphs. Depth-First Search (DFS) explores as far as possible along one branch before backtracking. It uses a stack (often via recursion) and is useful for tasks like cycle detection and topological sorting. Rapidly-exploring Random Tree (RRT) is a sampling-based algorithm used mainly in robotics and motion planning. It builds a tree by randomly sampling points in space and expanding toward them, making it effective in high-dimensional environments with obstacles.