Iterating over a Binary Tree with O(1) Auxiliary Space

Geez, I’ll have to actually type it up from Knuth. This solution is by Joseph M. Morris [Inf. Proc. Letters 9 (1979), 197-200]. As far as I can tell, it runs in O(NlogN) time. static void VisitInO1Memory (Node root, Action<Node> preorderVisitor) { Node parent = root ; Node right = null ; Node curr ; while (parent != null) { curr … Read more

Grammatical inference of regular expressions for given finite list of representative strings?

Yes, it turns out this does exist; what is required is what is known academically as a DFA Learning algorithm, examples of which include: Angluin’s L* L* (adding counter-examples to columns) Kearns / Vazirani Rivest / Schapire NL* Regular positive negative inference (RPNI) DeLeTe2 Biermann & Feldman’s algorithm Biermann & Feldman’s algorithm (using SAT-solving) Source … Read more

Are exceptions really for exceptional errors? [closed]

This sounds over-simplistic, but I think it makes sense to simply use exceptions where they are appropriate. In languages like Java and Python, exceptions are very common, especially in certain situations. Exceptions are appropriate for the type of error you want to bubble up through a code path and force the developer to explicitly catch. … Read more

Is Sleep() evil?

I actually believe the assertion you linked is correct. The problem is sleep is being used (as you noted) as an inefficient substitute for notification mechanisms. Sleep is always inferior to a properly implemented notification mechanism, If you are waiting for an event. If you actually need to wait a specific amount of time for … Read more