Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
Finding neighbouring nodes on a graph for the BFS algorithm

I'm trying to make an adjacency list for the breath first search algorithm and want find neighbouring nodes. I'm currently trying to look at each node on all rows and then either + 1 or - 1 for left and right neighbouring nodes.

const getNeighbours = (row, col) => {
  let neighbours = [];
  let left;
  let right;
  if(row > 0 ){
    neighbours[left] = [row - 1];
  }
  else if(row === 0){
    neighbours[right] = [row + 1]; 
  }
  console.log(neighbours[left])
} 

The graph is generated in a 2D array with rows and columns.

const createGrid = () => {
  let neighbours = [];
  let grid = [];
  for (let row = 1; row < 20; row++) {
    grid[row]= [];
    
    for (let col = 1; col < 47; col++) {
      grid = createNode(grid, row, col);
    }
    grid.push(grid[row]);
  }
  return grid;
};

The values I get for the getNeighbour is just 20 arrays with values of NaN. The graph has no edge cost and is undirected.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda