Recursion. This is one aspect that I’m still working on grasping, at least, within programming. In order to explain what this means within programming, I’m going to give an example from a current problem set I’m working on. First I’ll show you my code.
def countSubStringMatchRecursive(target, key, x): x = find(target, key, x) if x == -1: return 0 else: return countSubStringMatchRecursive(target, key, x+1) +1 target = ["atgacatgcacaagtatgcat", "atgaatgcatggatgtaaatgcag"] key = ["a", "atg", "atgc", "atgca"] for t in target: for k in key: print "There were " + str(countSubStringMatchRecursive(t, k, 0)) + " occurances of your key " + k + " in " + t |
At the beginning you can view my defined function. It’s highlighted in yellow. The definition of Recursion, as defined by wikipedia, is the process of repeating items in a self-similar way. For instance, when the surfaces of two mirrors are exactly parallel with each other the nested images that occur are a form of infinite recursion. The most common application of recursion is in mathematics and computer science, in which it refers to a method of defining functions in which the function being defined is applied within its own definition. The name of the function is “countSubStringMatchRecursive”, and both locations of the function are highlighted in red above.
One way to viewing recursion within literary aspects, would be to review a book by reviewing it’s chapters. Then review a chapter by reviewing it’s pages, then review a page by reviewing it’s paragraphs, then reviewing a paragraph by reviewing it’s sentences. Then you review the sentence’s grammar. Use each review and then amalgamate your data into one larger review in order to get the full picture of whether or not you like the author, or the book.
Within programming recursion can help to minimize your code, while still completing the same task. It can, however, make things more complicated to understand. It’s considered to be more elegant to use, in terms of creating code. Sometimes it isn’t always more helpful though. As a side note you should google recursion for fun, or just check it out on wikipedia.
Tomorrow I’ll continue on with explaining the code above.