Skip to content

Complete assignment 2 - #2

Open
tutoringjedi wants to merge 1 commit into
mainfrom
assignment-2
Open

Complete assignment 2#2
tutoringjedi wants to merge 1 commit 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

  • 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. It looks like you submitted A2 for the production module. Please double check and re-submit the correct file.

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