BST, the Find method and levelOrderForEach
CodeCara

CodeCara @codecara

About: Teaching myself web dev through The Odin Project. Started this blog to have some sort of record of my progress, as well as to hold myself accountable/keep myself on track while learning. (EN/ES/FR)

Location:
Europe
Joined:
May 11, 2024

BST, the Find method and levelOrderForEach

Publish Date: Aug 3
0 0

THINGS I’VE WORKED ON/COMPLETED…

The Find method in BST.

The levelOrderForEach in BST.

ISSUES I HAD…

In the levelOrderForEach method, I wasn’t entirely sure ‘how much’ should go into the callback (what to put in the callback v the main method, but I realised that if I created the array in the callback, that this would not work as a new array would be created each time. I asked for some advice about this and was told that it was perfectly acceptable for the callback to perform a simple task (console logging nodes visited in this case).

I tried to implement recursion in the levelOrderForEach method, but struggled with it - someone suggested to me that recursion might not be the best way to approach BFS, so I went with the iterative approach in the end.

My main method was originally put together using test data which created a balanced tree. When it came to testing the code I had (which was working), I realised how much more complicated things could get when nodes were added ‘manually’ using the insert method. I did manage to write code to accommodate all the edge case scenarios in the end, but it it probably lengthier than it could be. However, I decided to move on as I thought I had spent enough time on it. I should probably have thought more carefully about edge cases at the beginning, but it’s completed in any case.

My Xubuntu/Linux VM became corrupted - I lost quite a bit of time googling to find out what was happening (!) and understood only just enough to fix it. It’s amazing the problems you can fix, when you really have to.

THINGS THAT WENT WELL…

The find method was easy.

I started drawing out my trees to try to come up with useful pseudocode - this certainly helped.

THINGS I’VE LEARNT/NEED TO IMPROVE ON…

Consider edge cases from the beginning, as it may result in writing more efficient/concise code.

OTHER…

n/a

PLAN FOR THE UPCOMING WEEK…

So I didn’t have as much free time as expected during the week and only managed to finish two methods, with the second one taking longer than expected, so I am slightly reluctant to say I will finish BST.

However, there are just four methods left to complete and I really want to finish them/BST by next Sunday.

Comments 0 total

    Add comment