const levelOrderTraversal = (root) => { const result = []; // 결과를 저장할 배열 if (!root) return result; // 빈 트리일 경우 빈 배열 반환 const queue = [root]; // 큐를 초기화하고 루트 노드를 삽입 //queue라는 배열을 생성하고, 이진 트리의 루트 노드를 queue 배열에 넣는다. while (queue.length > 0) { const currentLevelSize = queue.length; // 현재 레벨의 크기 저장 const currentLevel = []; // 현재 레벨의 노드를 저장할 배열 for (let i = 0; i < currentLevelSize; i++) { const node = ..
class GraphWithAdjacencyMatrix { constructor() { this.matrix = []; } //이차원 배열(matrix)을 초기화 addVertex() { //버텍스를 추가합니다. const currentLength = this.matrix.length; for (let i = 0; i < currentLength; i++) { this.matrix[i].push(0); } this.matrix.push(new Array(currentLength + 1).fill(0)); //새로운 행(즉, 새로운 정점)을 만들고, 이를 matrix 배열의 끝에 추가 //새로운 정점은 다른 정점과 아직 연결되어 있지 않은 상태 //currentLength + 1 길이의 새로운 배열을 생성..