Skip to content

BFS-1 Completed #1644

Open
prattiiksha wants to merge 2 commits into
super30admin:masterfrom
prattiiksha:courseWork
Open

BFS-1 Completed #1644
prattiiksha wants to merge 2 commits into
super30admin:masterfrom
prattiiksha:courseWork

Conversation

@prattiiksha
Copy link
Copy Markdown

No description provided.

Pratiksha Kapse added 2 commits May 11, 2026 14:41
@super30admin
Copy link
Copy Markdown
Owner

Level Order Traversal in Binary tree (levelOrderTraversal_102.cpp)

Strengths:

  • Clean, readable implementation that matches the standard BFS approach for level order traversal
  • Proper handling of edge cases (empty tree)
  • Good variable naming conventions
  • Comments indicating complexity analysis
  • Correctly clears the path vector after each level to ensure proper separation of levels

Areas for Improvement:

  • Consider using path.clear() followed by path.shrink_to_fit() or simply creating a new empty vector each iteration for slightly better memory management, though this is minor
  • Could add comments explaining the algorithm logic for better documentation
  • The solution is functionally equivalent to the reference and doesn't need any changes

VERDICT: PASS


Scheduling Courses (course_scheudle_207.cpp)

Strengths:

  • Good choice of algorithm (Kahn's algorithm for topological sort)
  • Proper use of data structures (queue, unordered_map, inorder vector)
  • Handles edge cases like empty prerequisites and courses with no prerequisites

Areas for Improvement:

  1. Critical Bug: The inner loop for(auto [key,val]: map) should be replaced with direct access for(int neighbor : map[node]). This is the main correctness issue.
  2. Efficiency: The current map iteration inside the while loop is O(N) per node. Direct access would be O(degree of node).
  3. Code Clarity: Consider renaming variables for better readability (e.g., qqueue, countcompletedCourses).
  4. Logic Simplification: The count increment logic is duplicated - should only increment when a course is completed (when popped from queue), not when pushed.

Corrected approach:

while(!q.empty()) {
    int node = q.front();
    q.pop();
    for(int neighbor : map[node]) {
        inorder[neighbor]--;
        if(inorder[neighbor] == 0) {
            q.push(neighbor);
            count++;
        }
    }
}

VERDICT: NEEDS_IMPROVEMENT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants