For assignment 2 part 2, we were instructed to design four functions for the RegexTree class, which includes is_regex, all_regex_permutations, regex_match, and build_regex_tree. By working through this assignment, I have gained a better understanding of the RegexTree structure and recursion. For this post, I'll be writing about is_regex which is the function I had the most difficulty with.
In the beginning, I was coding in each individual invalid regex cases one by one. Even though I was making progress but after awhile it just seem off since I had too many lines of code. It was then I went on Piazza and took the advice of a fellow student and approached the function in a different way. First of all, I developed a base case for the Leaf. After that, I used recursion to solve the next level Regex, which is the StarTree. The tricky part is to figure out how to break the string down for the function to solve itself recursively. But once I got that, the code was simple to implement. This logic and approach enabled me to solve the BarTree and DotTree in a relatively short amount of time, since the approach is really identical.
This assignment has reinforced me on the importance of planning prior to writing up a recursion function.
No comments:
Post a Comment