The second assignment was due today. Fortunately, I was able to finish it several days ago. The first part of the assignment was fairly straight forward. The main challenge in this part was being able to recognize which node is the root node in a regular expression. As a human, one can immediately determine if a node is the root by checking how deep it is in the expression. Using this same logic, I kept track of the expression depth by having a running counter and adding one whenever a left bracket is reached, and also subtracting one whenever a right bracket is reached. This would be useful when checking if a node is the root (i.e. if the count is equal to one, then the node is found in the lowest depth of the expression and must be the root). This is the first approach that came to my mind. I am curious if there are others which people have implemented. Let me know in the comments.
I found the second part more challenging. The main challenge in this part (for me at least) was handling expressions with star nodes. This involved splitting up a string into several combinations of sub strings and checking that each sub string matches the RegexTree for at least one of those combinations. After spending quite some time trying to do this with loops, I was able to gain some helpful insight from Danny in lecture. For anyone who is stuck on this part, I strongly recommend following his advice and using recursion.
On an unrelated note, I mentioned a problem I had on the first test in my second blog post. After reviewing the solutions, I noticed that the __init__ method in question three was completely omitted from the class we were meant to implement. This makes much more sense, so that clears up my confusion I had for that question.
Anyway, good luck on your second assignments!
No comments:
Post a Comment