Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Breadth First Traverse | Practice
Breadth First Search
course content

Зміст курсу

Breadth First Search

Breadth First Search

1. What is BFS
2. Practice
3. Improve Your Code
4. Solving the Problems using BFS

Breadth First Traverse

The goal of this task is to create method BFT (Breadth First Traverse) to demonstrate the traverse. Consider that this method works only for some components, and the argument is the starting node. To keep track, you need to use a queue to push() and pop() objects. Here, you can use list for this and methods append() and pop(0).

When you traverse the graph, push nodes to the queue, that haven’t been visited yet. Thus, you need to track it in the visited array, which contains True, if node i is already visited, or False, if not.

Here is a BFS example again:

Завдання

Algorithm is next:

  1. Push start vertex to queue and label it as visited in visited array
  2. if the queue is not empty, go to the step 3. Else leave the function.
  3. Get the current node from queue, and push to the queue all unvisited neighbors. Label them as visited.
  4. Output which node you add and content of the queue on each step to demonstrate how it works.

Завдання

Algorithm is next:

  1. Push start vertex to queue and label it as visited in visited array
  2. if the queue is not empty, go to the step 3. Else leave the function.
  3. Get the current node from queue, and push to the queue all unvisited neighbors. Label them as visited.
  4. Output which node you add and content of the queue on each step to demonstrate how it works.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 2. Розділ 1
toggle bottom row

Breadth First Traverse

The goal of this task is to create method BFT (Breadth First Traverse) to demonstrate the traverse. Consider that this method works only for some components, and the argument is the starting node. To keep track, you need to use a queue to push() and pop() objects. Here, you can use list for this and methods append() and pop(0).

When you traverse the graph, push nodes to the queue, that haven’t been visited yet. Thus, you need to track it in the visited array, which contains True, if node i is already visited, or False, if not.

Here is a BFS example again:

Завдання

Algorithm is next:

  1. Push start vertex to queue and label it as visited in visited array
  2. if the queue is not empty, go to the step 3. Else leave the function.
  3. Get the current node from queue, and push to the queue all unvisited neighbors. Label them as visited.
  4. Output which node you add and content of the queue on each step to demonstrate how it works.

Завдання

Algorithm is next:

  1. Push start vertex to queue and label it as visited in visited array
  2. if the queue is not empty, go to the step 3. Else leave the function.
  3. Get the current node from queue, and push to the queue all unvisited neighbors. Label them as visited.
  4. Output which node you add and content of the queue on each step to demonstrate how it works.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 2. Розділ 1
toggle bottom row

Breadth First Traverse

The goal of this task is to create method BFT (Breadth First Traverse) to demonstrate the traverse. Consider that this method works only for some components, and the argument is the starting node. To keep track, you need to use a queue to push() and pop() objects. Here, you can use list for this and methods append() and pop(0).

When you traverse the graph, push nodes to the queue, that haven’t been visited yet. Thus, you need to track it in the visited array, which contains True, if node i is already visited, or False, if not.

Here is a BFS example again:

Завдання

Algorithm is next:

  1. Push start vertex to queue and label it as visited in visited array
  2. if the queue is not empty, go to the step 3. Else leave the function.
  3. Get the current node from queue, and push to the queue all unvisited neighbors. Label them as visited.
  4. Output which node you add and content of the queue on each step to demonstrate how it works.

Завдання

Algorithm is next:

  1. Push start vertex to queue and label it as visited in visited array
  2. if the queue is not empty, go to the step 3. Else leave the function.
  3. Get the current node from queue, and push to the queue all unvisited neighbors. Label them as visited.
  4. Output which node you add and content of the queue on each step to demonstrate how it works.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

The goal of this task is to create method BFT (Breadth First Traverse) to demonstrate the traverse. Consider that this method works only for some components, and the argument is the starting node. To keep track, you need to use a queue to push() and pop() objects. Here, you can use list for this and methods append() and pop(0).

When you traverse the graph, push nodes to the queue, that haven’t been visited yet. Thus, you need to track it in the visited array, which contains True, if node i is already visited, or False, if not.

Here is a BFS example again:

Завдання

Algorithm is next:

  1. Push start vertex to queue and label it as visited in visited array
  2. if the queue is not empty, go to the step 3. Else leave the function.
  3. Get the current node from queue, and push to the queue all unvisited neighbors. Label them as visited.
  4. Output which node you add and content of the queue on each step to demonstrate how it works.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 2. Розділ 1
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt