Linked lists and assignment 2 were the main topics for this week, both of which were very interesting. A linked list is not really a list in the strictest sense, it is more a recursive data structure: the entire list is contained within the root node of the tree. Each node has two attributes, its value and the next node. Thus, the only reference needed to the list is one to the root node, with the danger that if this node was at any instance not referenced to, the entire list would be destroyed by garbage collection within Python.
A linked list is to be used in binary tree form for assignment 2, which requires the parsing of a regular expression into a binary tree. My group has already finished step 1, but step 2 proposes some difficulties, especially the star node, which would possibly require comparing every possible combination of it to the matching string, and bar node, in some very specific cases.
Monday, 28 October 2013
Sunday, 20 October 2013
Week 6: Oct 14 - 20
This week was the Midterm for 148, as well as an exploration of trees, data structures that are organized recursively. Due to its recursive nature, trees are best created and read recursively, although they can be converted back to lists using three methods (which create lists with the same elements but in different order): preorder, inorder and postorder. These methods are known as traversal methods and are ways to step through all nodes once each, using only the connections between parent and children nodes. Though at first I didn't know of why anyone would prefer using a data structure such as a tree over just a regular list, I learned many applications for trees this week.
One of the best uses of a tree is to search for values, as demonstrated earlier in an exercise. By making sure that one branch of the tree is larger than the root node, and the other smaller, you can significantly speed up the search process, as long as converting the initial set of values into such a tree is efficient enough.
One of the best uses of a tree is to search for values, as demonstrated earlier in an exercise. By making sure that one branch of the tree is larger than the root node, and the other smaller, you can significantly speed up the search process, as long as converting the initial set of values into such a tree is efficient enough.
Sunday, 13 October 2013
Object Oriented Programming
One of the major advancements of programming languages, object orientation really allows development of a programming language outside of initial development. Rather than a long list of commands, supplemented occasionally with functions to reduce repetition, object oriented programming allows for the bundling of functions and variables these functions operate on into objects, and therefore programming in an object oriented can be seen as creating interactions between objects rather than the data itself. This additional layer of objects allows the programmer to not only reuse methods that he has created with the attributes that he has created with them, it also allows him to use other people's objects. The additional level of privacy and security offered by the object system allows this to a degree simply using functions cannot. Thus, with the development of object oriented programming, the world of programming was taken to a whole new level.
Recursion
It is a deceptively simple process, create a method that calls itself, breaking a bigger problem into identical, smaller problems, until the problem becomes trivially easy to solve. While the ending case can usually be easily envisioned, and the starting case given, it is therefore in the middle that is the hardest part of a recursive program, the few lines of code that divide the problem into smaller problems, and calls upon itself accordingly. Therefore, though it could be confusing to follow, recursive programs are simple to understand due to only requiring the few lines of code, each a reference to itself or the terminating case.
Week 5: October 7 - 13
This week:
This week's exploration about recursion is very interesting: recursion simplifies code, often converting over ten or twenty lines of code into a single line of code. The main problem with recursion is finding that one line of code in the first place, it is very easy to get infinite recursion even if an ending case is used, but perhaps not all of the endings are covered.
This is the main difficulty I had with the idea of recursion, and therefore assignment 1, which used it heavily. With iterative programs, which will tell you which line of code has an error and allows you to focus upon it, recursive programs are not so easily debugged. A single line of code, forgotten case or even misplaced command can have one reading through the code for up to an hour trying to fix it. The worst case is when it works, but not the way that you expect. There's just no real way to solve this problem other than going through the program (which often requires going through the method many, many times). Therefore, though I believe recursion is great when done correctly, it is very troublesome to fix when there is even the smallest error.
Therefore, to help with this problem, I've often started at the output when writing recursive programs. While most iterative programs require thinking from the start and creating a path to the ending output, I find it easier to start at the terminating case and work backwards. This is the technique that I plan to use for recursive programs in general.
This week's exploration about recursion is very interesting: recursion simplifies code, often converting over ten or twenty lines of code into a single line of code. The main problem with recursion is finding that one line of code in the first place, it is very easy to get infinite recursion even if an ending case is used, but perhaps not all of the endings are covered.
This is the main difficulty I had with the idea of recursion, and therefore assignment 1, which used it heavily. With iterative programs, which will tell you which line of code has an error and allows you to focus upon it, recursive programs are not so easily debugged. A single line of code, forgotten case or even misplaced command can have one reading through the code for up to an hour trying to fix it. The worst case is when it works, but not the way that you expect. There's just no real way to solve this problem other than going through the program (which often requires going through the method many, many times). Therefore, though I believe recursion is great when done correctly, it is very troublesome to fix when there is even the smallest error.
Therefore, to help with this problem, I've often started at the output when writing recursive programs. While most iterative programs require thinking from the start and creating a path to the ending output, I find it easier to start at the terminating case and work backwards. This is the technique that I plan to use for recursive programs in general.
Subscribe to:
Posts (Atom)