Through most of our recent classes weāve gone in depth with the concept of OOP (Object Oriented Programming). OOP allows a particular program to be broken down into many smaller modules or āobjectsā. For example, in Python a string is an object. In this case, itās a sequence of characters which have certain characteristics or āattributesā, like their length and also certain functions or āmethodsā that can be applied to it. One of the biggest advantages of OOP is that it lends itself fantastically to teamwork. When various parts of a program are divided, it allows people to go off and work on a single part, and then in the end, come back and put it all together. In short, OOP allows programmers to abstract ideas from the real world and represent them in a program.
Another new concept weāve gotten to interact with is of recursion been introduced into our course. Recursion is essentially the idea of breaking a task down into smaller bits, until the pieces of the task are small enough to be solved very easily, and then finding the solution by rebuilding all the solved pieces together. Without this concept, a lot of programming problems can be unnecessarily difficult. Initially I found the concept a little intimidating however I feel by now Iāve comparatively gotten more comfortable with the concept. Ā Iāve reached a stage where I enjoy playing around with it and find new ways to implement it.
An example of a recursive function would be a function that calculates the nth fibonacci number. If you were asked to find the eighth fibonacci number, youād have to find out the sixth and seventh numbers? In order for that, youād have to calculate the fourth and fifth, and then the second and third, and so on. By the end of its implementation we end up with a simple and short solution, as opposed to the mountain of complications a non-recursive solution would entail.
One of the basic uses of recursion can be found in trees. A tree will have some value, and would further have children that are trees with their own children, which are trees, and so on. To find a certain value within a tree, youād go through the following steps
Look for the search value in this treeās value.
If you havenāt found the value and the tree has children, look for it in this treeās children. If there are no children, the value is not in this tree.
Hence, recursion usually leads to very readable, simple, code which can solve seemingly much more complex problems.