Skip to content

Create bfs1.java - #1658

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

Create bfs1.java#1658
Praniksha123 wants to merge 1 commit into
super30admin:masterfrom
Praniksha123:master

Conversation

@Praniksha123

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Binary Tree Level Order Traversal (bfs1.java)

Strengths:

  • Your BFS implementation is correct and clean
  • Good handling of edge cases (null root)
  • Clear variable naming
  • Proper use of Queue and List data structures

Areas for improvement:

  • The file contains two separate solutions (problem1 and problem2). It's best practice to keep each problem's solution in its own file. The second solution (canFinish) appears to be for a different problem and should be removed or placed in a separate file.
  • Consider adding comments to explain the algorithm approach
  • The indentation in the second solution (canFinish) is inconsistent, which affects readability

VERDICT: PASS


Course Schedule

Strengths:

  1. Your solution correctly implements Kahn's algorithm for topological sorting, which is an excellent alternative to DFS for cycle detection.
  2. The time and space complexity match the optimal solution.
  3. You correctly handle the in-degree tracking and adjacency list construction.

Areas for improvement:

  1. File organization: Your file contains two unrelated solutions (levelOrder and canFinish). Each problem should be in its own file with appropriate class names.
  2. Indentation: The indentation is inconsistent and makes the code hard to read. Make sure to properly indent all code blocks.
  3. Variable naming: Use more descriptive names. For example, de could be dest, in could be src, preq could be prereq, li could be neighbors, l could be neighbor.
  4. Redundant check: The if(q.isEmpty()) return false; check is unnecessary. The final return cnt == numCourses; already handles this case correctly.
  5. Code style: Consider adding comments to explain the algorithm steps for better readability.

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