Skip to content

Solved Binary Tree Level Order Traversal and Course Schedule#1647

Open
anirudhv98 wants to merge 1 commit into
super30admin:masterfrom
anirudhv98:master
Open

Solved Binary Tree Level Order Traversal and Course Schedule#1647
anirudhv98 wants to merge 1 commit into
super30admin:masterfrom
anirudhv98:master

Conversation

@anirudhv98
Copy link
Copy Markdown

Completed BFS-1, please review.

@super30admin
Copy link
Copy Markdown
Owner

Level Order Traversal in Binary tree (Problem1.cs)

Strengths:

  • Clean and readable implementation that matches the standard BFS approach for level order traversal
  • Good use of early return pattern for null root
  • Proper handling of left and right children
  • Well-documented with time/space complexity comments
  • Correctly uses IList<IList> as the return type, which is appropriate for LeetCode

Areas for Improvement:

  • The solution is functionally equivalent to the reference and doesn't have significant issues
  • Minor suggestion: Could consider using var for local variables like tempList for brevity, though this is stylistic

VERDICT: PASS


Scheduling Courses (Problem2.cs)

Strengths:

  • Correctly implements topological sort using Kahn's algorithm
  • Good variable naming (adjMap, inwardCount, q)
  • Proper handling of edge cases
  • Clean and readable code structure
  • Appropriate use of C# collections

Areas for Improvement:

  • The adjacency list direction could be more intuitive. Currently storing adjMap[course] = list of prerequisites, but the standard approach typically stores adjMap[prereq] = list of courses that depend on it. This works but may be slightly confusing to maintain.
  • Could add null checks or use TryGetValue to avoid repeated ContainsKey checks
  • The initial count increment (count += 1) for zero in-degree courses could be moved inside the while loop for better consistency

Overall, this is a solid solution that correctly solves the problem with good complexity characteristics.

VERDICT: PASS

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