Skip to content

Assignment 2 - #3

Open
tutoringjedi wants to merge 2 commits into
mainfrom
assignment_2
Open

Assignment 2#3
tutoringjedi wants to merge 2 commits into
mainfrom
assignment_2

Conversation

@tutoringjedi

Copy link
Copy Markdown
Owner

What changes are you trying to make? (e.g. Adding or removing code, refactoring existing code, adding reports)

Added the completed assignment_2.ipynb, which includes: a solution to the assigned Part 1 coding problem (Path to Leaves using DFS with backtracking), a code review of my partner's Assignment 1 submission (Valid Bracket Sequence), and a written reflection on both assignments.

What did you learn from the changes you have made?

I learned that DFS with backtracking is better suited than BFS for collecting root-to-leaf paths, because the call stack naturally tracks the current path without needing to store copies alongside every queue element. Through the code review process, I also learned to read code critically for edge cases — I identified a bug in my partner's solution that causes an IndexError when a closing bracket is encountered on an empty stack (e.g. input ")(").

Was there another approach you were thinking about making? If so, what approach(es) were you thinking of?

For the Path to Leaves problem, I initially considered BFS. While BFS works, it requires storing a copy of the current path with every node in the queue, making it less memory-efficient than the DFS + backtracking approach, which reuses a single list.

Were there any challenges? If so, what issue(s) did you face? How did you overcome it?

The main challenge was ensuring the path list was correctly snapshotted at each leaf node. Since the same list is mutated throughout the recursion, calling results.append(path) would store a reference that changes as backtracking continues — so I used results.append(list(path)) to capture a copy at each leaf.

How were these changes tested?

The bt_path function was tested against all examples provided in the assignment, plus two additional cases: a single-node tree (where the root is also the only leaf) and a right-skewed tree. All outputs matched expected results.

A reference to a related issue in your repository (if applicable)

Checklist

  • [X ] I can confirm that my changes are working as intended

@tianyi21 tianyi21 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Neil,

Thank you for submitting your ADS A2. Please find my feedback below:

Part 1

✅ You implemented an algorithm to find all root-to-leaf paths in a given tree.
✨ You implemented a DFS-based recursive algorithm to solve the question.
✅ Your program runs successfully without any errors.
✅ Your program produces the intended results.

Part 2-3

✅ You correctly explained your partner's implementation and analyzed its time and space complexities.

Part 4

✅ You included a paragraph to explain your experience and thoughts to us.

🎉 All your ADS assessments are now complete. Thank you for your participation.

Thanks,
Tianyi [LS]

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