Skip to main content
Practice

coding-quiz-2

---
id: coding-quiz-2
title: Coding Quiz - Order of Visits (BFS)
description: Coding quiz to print the order of visits using BFS
tags:
- coding quiz
- BFS
- Python
sidebar_position: 9
isPublic: false
---

# Coding Quiz

In this coding quiz, you are tasked with writing a program that uses the Breadth-First Search (BFS) algorithm to begin at a specific node of a graph and visit all the nodes.

The user will provide an adjacency list representing the nodes in the graph and their connections. Write a program to perform BFS starting from a specific node and print the order in which all nodes are visited.

<br />

```python title="Write Code"
def solution(graph):
# Write your code here
return



Constraints

  • The graph is an undirected graph.

  • All nodes are represented by numbers, starting from 1.

  • The graph has at least one node and at most 100 nodes.

  • There is at most one edge between any two nodes.

  • The starting node is always node 1.




Input and Output Example

Input

  • Adjacency List: {1: [2, 3], 2: [4], 3: [4], 4: []}

  • Starting Node: 1

Output

  • Order of Visits: [1, 2, 3, 4]

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.