Input: adj = [[1,2], [0,2,3], [0,4], [1,4], [2,3]]

Output: [0, 1, 2, 3, 4]
Explanation: Starting from 0, the BFS traversal will follow these steps:
Visit 0 → Output: [0]
Visit 1 (first neighbor of 0) → Output: [0, 1]
Visit 2 (next neighbor of 0) → Output: [0, 1, 2]
Visit 3 (next neighbor of 1) → Output: [0, 1, 2,3]
Visit 4 (neighbor of 2) → Final Output: [0, 1, 2, 3, 4]
Input: adj = [[1, 2], [0, 2], [0, 1, 3, 4], [2], [2]]
Output: [0, 1, 2, 3, 4]
Explanation: Starting from 0, the BFS traversal proceeds as follows:
Visit 0 → Output: [0]
Visit 1 (the first neighbor of 0) → Output: [0, 1]
Visit 2 (the next neighbor of 0) → Output: [0, 1, 2]
Visit 3 (the first neighbor of 2 that hasn’t been visited yet) → Output: [0, 1, 2, 3]
Visit 4 (the next neighbor of 2) → Final Output: [0, 1, 2, 3, 4]
Input: adj = [[2, 4], [3], [0, 4], [1, 4], [0, 2, 3]]
Output: [0, 2, 4, 3, 1]
Explanation: Starting the BFS from vertex 0:
Visit vertex 0 → Output: [0]
Visit vertex 2 (neighbor of 0) → Output: [0, 2]
Visit vertex 4 (next neighbor of 0) → Output: [0, 2, 4]
Visit vertex 3 (unvisited neighbor of 4) → Output: [0, 2, 4, 3]
Visit vertex 1 (unvisited neighbor of 3) → Final Output: [0, 2, 4, 3, 1]
Time Complexity: O(V + E), BFS explores all the vertices and edges in the graph. In the worst case, it visits every vertex and edge once. Therefore, the time complexity of BFS is O(V + E), where V and E are the number of vertices and edges in the given graph.
Auxiliary Space: O(V), BFS uses a queue to keep track of the vertices that need to be visited. In the worst case, the queue can contain all the vertices in the graph. Therefore, the space complexity of BFS is O(V).