BFS Preparation Queue

Medium Queue: Applications PRO
🔒 Login to Unlock

Problem Statement

Write a C program to simulate a Breadth-First Search (BFS) level-order traversal queue on a simple graph/tree adjacency list.

Input Format

First line contains number of nodes and start node. Subsequent lines contain edges.

Output Format

Print visited nodes in BFS traversal order separated by spaces.

Constraints

1 <= nodes <= 20

Sample Input

4 0
0 1
0 2
1 3

Sample Output

0 1 2 3

Explanation

Use a standard queue to track nodes to visit, marking them as visited and enqueuing their unvisited neighbors.

Starter Code

#include <stdio.h>
#include <stdlib.h>

int main() {
    int n, start;
    if (scanf("%d %d", &n, &start) == 2) {
        // Write your code here for BFS traversal queue preparation
    }
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used