The assignments are now wrapped up, embalmed, buried. Good good.
This last one in particular was a bit of a struggle towards the end -- our code was developed very smoothly and efficiently, but with lots of clumsy extra parts, long strings of redundant code and a lack of polish despite the fact that it worked relatively well.
So we tore out its guts and rebuilt it. And there were a few scares when you realize a thing or two went missing during the process. One example was our implementation of regex_match, which took the longest of everything -- at one point, we were gathering every conceivable example which would work with a string, which led to exponential runtime for our niggling StarTree. We were able to fix that by taking out the helper function altogether and allowing regex_match to return recursive bools to answer other bools. Our StarTree ended up checking slices of the the indices of the string along the string's length until it found an example which conformed to the tree we were after, breaking it up into little pieces.
But then, horror of horrors, BarTree was returning True for things which should return False. Again, pen and paper had to leap to work to visualize what exactly was being done by the code to make it keep making this mistake. Lo and behold, there was an unnecessary line of code - a 'for' loop left over from the StarTree. What was lovely about BarTree is that the comparison was ultimately very simple: it's either one side of the bar, or the other side of the bar. Nothing else matters.
That, though it was a revelation within the final hours of our time with A2, proved exceptionally helpful in understanding the inner workings of the assignment and why the trees were an effective way of storing regex information.
Rather than relying on a string, which requires all manner of complicated indexing to break apart each time you want some information, a tree holds it all neatly and allows effective recursion. Checking the inside of another pair of brackets? Go a level deeper. Especially useful was the fact that the tree system made it easily visible what was or wasn't needed to investigate the code. You don't need to worry about a StarTree having a DotTree inside until you provide the answer to the DotTree. The StarTree cannot affect the DotTree's result. Understanding this albeit basic concept did greatly aid in contextualizing how our functions worked.
After the assignment is done, our sights are now turned to the midterm, and to runtime again. I can say that I understand the way runtime works, although I am not entirely sure that I can safely navigate it without a good bit of brain-training, which will undoubtedly be occurring for most of the week leading up to the midterm. I am sure I will have to revisit some 108 notes on sorting, but that should be a boon in and of itself anyway.
No comments:
Post a Comment