Programmer's Guide To Theory - Turing Thinking |
Written by Mike James | |||||||
Wednesday, 18 June 2025 | |||||||
Page 3 of 3
This algorithm is an example of Turing thinking. The algorithm ignores any issue of what resources are needed. It is assumed that pushes and pops will never fail for lack of resources. The algorithm is a Turing machine style unbounded algorithm that will deal with a string of any size. Now consider a finite machine approach to the same problem. We need to set up some states to react to each ( and each ) such that if the string is balanced we end in a final state. In the machine below we start from state 1 and move to new states according to whether we have a left or right parenthesis. State 5 is an error halt state and state 0 is an unbalanced halt state.
(())() state 1 → state 2 ())() state 2 → state 3 ))() state 3 → state 2 )() state 2 → state 1 () state 1 → state 2 ) state 2 → state 1 and as we finish in state 1, the string is balanced. (()))( state 1 → state 2 ()))( state 2 → state 3 )))( state 3 → state 2 ))( state 2 → state 1 )( state 1 → state 0 as we finish in state 0, the string is unbalanced. Finally consider: (((()))) state 1 → state 2 ((()))) state 2 → state 3 (()))) state 3 → state 4 ()))) state 4 → state 5 as we finish in state 5, an out of memory error has occurred. The difference between the two approaches is that one doesn’t even think about resources and uses the pattern in the data to construct an algorithm that can process any amount of data given the resources. The second deals with a problem with an upper bound – no more than four left parentheses can be processed. Of course, this distinction is slightly artificial in that we could impose a bound on the depth of the stack and include a test for overflow and stop the algorithm. Would this be finite state thinking or just Turing thinking with a fix for when things go wrong? The point is that we construct pure algorithms that tend not to take resource limitations into account – we think Turing, even if we implement finite state. There is also a sense in which Turing thinking captures the abstract essence of the algorithm that goes beyond a mere mechanism to implement it. The human mind can see algorithms that always work in principle even if in practice they have limits. It is the computer science equivalent of the mathematician conceiving of a line as having no thickness, of a perfect circle or indeed something that has no end. Summary
A Programmers Guide To Theory
Now available as a paperback and ebook from Amazon.Contents
To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
Comments
or email your comment to: comments@i-programmer.info |
|||||||
Last Updated ( Wednesday, 18 June 2025 ) |