Sunday, April 5, 2015

Last Impressions

Looking back over the course, the new concepts are not too difficult to understand and implement. Gradually building up to harder and harder concepts, makes learning them much easier. We began to learn recursion, for example, by tracing code and going over simple and more complex examples. By learning to understand how recursion works, we learn the basis behind recursive code and how to write it. After tracing recursive code, we began to write and implement simple recursive functions and step by step learned how to write our own recursive code. Learning this way, makes it simpler and easier. Additionally, learning object oriented programming, rather than other ways to program, made coding games (i.e assignments) more time efficient and expanded our knowledge of python. By using object oriented programming in this course, we were able to write classes and subclasses for games such as tippy and subtract square. This made it more time efficient and easy to code these games, since they were all subclasses and used inheritance. We can add our own games now to the class and expand our code, particularly the game view, which asks the user what game they wish to play (tippy or subtract square). This can be expanded to other games (as long as they are zero sum and sequential).

For this course, there was many conceptual hurdles I had to jump over. I personally found recursion difficult. Even by learning one step at a time, slowly and patiently, I still found the concept, particularly writing and implementing recursive code, hard. One way I learned to jump this specific hurdle was by using the python visualizer to "see" the implementation of the code and understand how it works. Another way, was by using a sort of formula when writing recursive code. By imagining the most simplest example and writing an if statement for that and then imagining a more complex example and writing the recursive part of the function for that example. In general, practice makes perfect, and by practicing recursive code, I was able to become a better programmer.

Course events for this course, such as assignments and tests went well, in general. I had trouble with most of the assignments, since there were always bugs I had to deal with. I may have also started the assignments too late and I didn't have enough time to debug my code and fix the problems. Looking back, I should have begun the assignments as soon as they were posted and throughout the weeks worked on them, even for just a few minutes. Personally, tests went better. All in all I had a great impression of this course and I would definitely recommend it to other students.     

Tuesday, March 31, 2015

Revisiting ADTs

For this post, I am going to be revisiting the concept of ADTs, Abstract Data Types. In my past slog entry about Abstract Data Types, I said that they consisted of stacks and subclasses. I also mentioned that I found it difficult to implement stacks and the concept of inheritance. Furthermore, I commented on Assignment 1, which was due earlier that week and which I had a slightly difficult time completing. However, after rereading the entry and revisiting those comments, I've found that I did not clearly or completely discuss this concept. Additionally, I also realized that the topics placed under ADTs was narrow. Through later weeks in this course, I've learned more ADTs that can be added along with stacks and subclasses, for instance trees and linked lists.

An abstract data type (ADT) is a model of data types, which are defined by behavior rather than the representation of data. This behavior is from the perspective of the user of the data, not the implementer. This is usually in terms of values, operations and the behavior of those operations. An ADT is  a "class of objects whose logical behavior is defined by a set of values and a set of operations." As mentioned in the previous entry, stacks and queues are abstract data types. Now, weeks later I can add more to this short list. Trees, linked lists, and BSTs are other abstract data types. While individually a tree and a stack are vastly different, and each has its own advantages and disadvantages for when to implement them, they both fall under the term of ADTs. This may take a while to fully understand, but once it did, the concept really clicked. The applications and uses of ADTs are very diverse and vast.

Looking through my classmates slogs, its clear to see that they also have been able to fully understand the concept of ADTs better. Being able to understand and identify trees, lists, stacks and queues as Abstract Data Types is very important, especially for object-oriented programming. Or as one class mate put it: "Object Oriented Programming is focused on using custom classes with various special methods and properties included, some of which serve as Abstract Data Types (like lists, stacks, queues, trees)." . Another classmate, when discussing stacks and trees, mentions that they are also abstract data types. Being able to connect the concepts we learn now with previous concepts learned earlier in the course, is crucial, especially when implementing them. This also makes it easier to learn, when you group similar concepts together, and having a broad term to use when talking about vastly different objects, (such as a tree and a stack) makes it easier to get a point or an idea across, as well as making it able for a programmer to get his thoughts across in a short, concise manner (in as little words as possible).

Sunday, March 22, 2015

Week 9 Impressions: Mutating BSTs

Last week, (week 9) we had our second and final test for the semester. The test covered topics from weeks 5-8, and concepts such as tree definitions (travelling through trees using postorder, inorder and preorder traversals), recursive functions, binary trees and binary search trees, as well as linked lists. We were also allowed an aid sheet. In general, I didn't find the test to be too difficult, some concepts, especially the newer ones, such as linked lists were harder to understand. Since the test occurred during lecture time, we did not go over much in class. In fact we had less than an hour for the lecture last week.

Earlier in the semester we learned about Binary trees and Binary Search trees, a way of  organizing data in trees such that they are easier and more efficient to search through. In class last week, we wrote a function called insert that inserted data starting at node, and returned the root. We examined the code (def insert) and talked about a new function for deleting data instead of inserting data. In the function for inserting data, we wrote a recursive function. Taking in a node and data, the function should insert the data at the node and return the root. Starting by assigning the node to a new variable, called return_node, we then wrote an if statement for the simplest example, where there is no node (if not node:), if that is the case, then the variable return_node should be assigned the new data. If the new data is less than the data at the node, then the data is inserted in the left node, else if it is greater than the data at node, then it is inserted to the right. This is a property of binary search trees (greater values are on the right and smaller values on the left of the node). Finally if there is nothing else to do, (else statement), return_node should be returned. This code is easy to understand, especially after breaking it down like I did above. By going through the code line by line and "reading" the if's, elif's and else statements, you can understand what the code does, even if there is no docstring description.

Finally, in class we went over, briefly a function for deleting data from a binary search tree (BST) rooted at node. In order to write a function for deletion of data, we had to first understand and write a general algorithm for delete. This is both to understand what we want the function to do and also to make writing it more simple and easier. Our algorithm for delete, is to first see if node is None, if True then return that node. Next, we want to check if the data is less than the data at the node (like we did in the insert function). If it is we delete it from the left child and return this node. Third, we check if the data is more than the node.data, and delete it if it is from the right child, returning this node. The fourth case we can have, is that the node has fewer than two children. If that is the case, then one must be None, and must therefore return the other one. Finally if the node has two non-None children (i.e there is data for both the right and left), then the data must be replaced with that of its largest child in the left subtree. That child is then deleted and the new node returned. Looking at the code, its clear that this is what happens, and that by writing out an algorithm first, it was easier to write the code.

Thursday, March 12, 2015

Week 8 Impressions: Linked Lists

Last week the TA's went on strike. Therefore, we didn't have any labs during the week. The lab handout was still available, but there were no lab quizzes, and no one had to show up to their weekly scheduled labs. This meant, that while there were still questions and functions to write and implement, there was no TA to ask for help, when stuck and needing guidance. Beyond this inconvenience, the lecture was understandable and I didn't have any more trouble solving the lab problems. The discussion board was a good place to go, especially this week, when I had trouble with the lab. Also the solutions were posted for the lab, so I had the answers and when stuck I could work back from the solution and understand how they got to that code.

In class, we learned about linked lists. We also learned of two different, but very useful ways to think about linked list structures. The first way to think of them is as lists made up of an item (value) and a sub-list (rest). The second way of thinking about linked lists is as objects (nodes) with a value and a reference to other similar objects. This sounds complex but what it really translates into is a list within a list, or a tree with a branching factor of one, meaning one node points to another, which points to another and so on. Linked lists also need a "wrapper" class. This class represents the linked list as a whole and keeps track of information about the entire list, including its front, back and size. This class initializes these variables as the most basic and simple list (an empty linked list) with size 0, and the front and back both initialized to None.

Furthermore, we learned how to "walk" across a linked list, as in how to write code that can check the nodes of a linked list. In that code, we made a reference (to at least one) other node and then moved the code along the list. We then added and modified to the code so that is checks every possible node in a linked list ( _contains_ ). Afterwards, we wrote code for an append method, which does several things: change the last node, the former last node, the back, the size (adding one as an item is appended to the list), as well as possibly the front. A question concerning linked lists was on Test 2, which we had this week. Understanding and learning how to implement functions for linked lists was something I found slightly difficult for this week. However, by working through the problems in the lab handout and by playing around with the class code, I was able to gain a more thorough understanding of the concept. Programming really is a hands on subject; to learn more efficiently and effectively all you have to do is code more.    

Sunday, March 8, 2015

Week 7 Impressions: Binary Trees

During week 7 for this course, we continued learning about Trees, this time Binary Trees. Binary trees are a specific type of trees in which each node can have at most two children (left and right). Binary trees can be have ordering conditions. This is very useful, since with an ordering condition, a binary tree is more efficient and easier to search through. If it is known that the higher values are on the right of a node and lower values are on the right, then searching through the tree is not only easier, it's also more efficient.  Also, using a binary tree, we can create a code so that the program searches through the tree without having to stop at and search through unnecessary nodes. For example, if we are searching for 8 in a binary tree and self.data (or the value at the first node) is 4, then we know that the code does not have to stop at the node on the left, since it would be less than 4, and 8 is obviously greater than 4. Using a binary tree in this manner, makes searching through large amounts of data more quick and efficient. Additionally there are more than one way of searching through a binary tree: inorder, preorder, and postorder.

Inorder searching is a way of searching through binary trees, where it visits the left subtree inorder, then visits the node itself, then visits the right subtree inorder. This code is recursive. Preorder, on the other hand, is different, since the node itself is visited first, then the left subtree in preorder, then the right subtree in preorder. Finally, post-order searching is when the left subtree is visited first in postorder, then the right subtree in postorder, then the node itself. In all cases, the left subtree is always visited before the right subtree. 

Furthermore, in last week's lab, we created recursive code for a binary tree. This was difficult at first, especially writing the recursive part of the code. In order to create recursive code, you must first understand the most basic and simplest example, which does not require recursive code. This part usually the easiest since it does not require any recursion and is just a simple 'if' statement. Afterwards, you must think of the most simplest example that does require a little recursion. After, write the recursive code for this simple recursive example. This part is much more difficult, and takes some practice and understanding. However, afterwards it becomes much more easy to write and implement recursive code. For one part of the lab last week, we had to write code to search through a binary tree without stopping at unnecessary nodes. As mentioned above, this meant we had to use the properties and ordering conditions of a binary tree already explained. This code was also recursive and was easier to understand and visualize than to write and implement. However, once the most basic example was thought of and code written for, the rest flowed naturally.  

Sunday, March 1, 2015

Week 7: Recap on OOP

For this week, please grade my summary on Object Oriented Programming: found here.

To recap, what I've written on Object Oriented Programming:
OOP (Object-oriented programming) is simply a model for programming. It is centered on objects (obviously) as well as data. This differs from other models for programming languages, which typically are centered around actions and logic. Objects are abstract data types (ADTs). Furthermore, objects contain data, called attributes and code, called methods. Data classes, such as those used in Assignment 1 and in labs, are important in defining subclasses, as well as for creating special types of classes, like Stacks, Trees, and Queues. Inheritance, which is important for coding subclasses, is a more efficient way of programming (than to manually program each class). Through subclasses, those classes that share similar functions and methods, can also share code. The programmer would not have to write code twice (or copy and paste code, which can cause errors to occur). Therefore, Inheritance is more time efficient as well as a more accurate way of coding (less errors will occur). 

Additionally, through object-oriented programming, programmers can create trees, which are extremely useful. Through a binary search tree, in particular, a programmer can search through thousands of options more quickly and efficiently. Since the binary search tree is set up in such a way that data is comparable. The data at the nodes to the left are less than data.node and those to the right are greater. Thus a programmer can write code to search the tree without having to search all the nodes in the tree, since it would know that is does not have to stop at the left or right node, according to the value it is searching for and the value at the data.node. Also, as when used in Assignment 1, object-oriented programming, can be used to make a general class with more specific subclasses, which can be used for other games (such as Subtract Square, Tippy, or Tic-Tac-Toe). Using object-oriented programming is very useful and has numerous advantages. 

Monday, February 16, 2015

Week 5: Object- Oriented Programming

Object-oriented programming (OOP) is a model for programming language centered and modeled around objects and data, rather than actions or logic. Traditionally, a program was seen as just a logical procedure that takes an input data, and after processing it, returns an output data. Furthermore, as stated earlier, object-oriented programming is based on objects. Objects are abstract data types. They are structures that contain data, often known as attributes, and code, known as methods. Additionally they have both a state (data) and behavior (code).

In this type of programming (object-oriented), the programs are designed to interact with one another. While, there are diverse ways of object-oriented programming, most languages are class-based. This means that the objects are instances of classes; this determines their type. Python, C#, C++, Java, Perl, and many other computer languages are significant object-oriented languages. In class, we have been learning object-oriented programming and concepts. Object-oriented programming concepts, then are concepts such concepts as learned in class, such as classes, subclasses (and Inheritance), stacks, queues, and trees.

The concept of data class, makes it possible to define subclasses of data objects, that share some of the main class characteristics or attributes. The process of inheritance, which is crucial to programming subclasses, is a more efficient way of coding, since it reduces time spent programming the same functions as well as ensure a more accurate code. Additionally, the concept of classes allows a programmer to create a new data type not already defined in the language itself. This is useful for many reasons. One of the main reasons, classes are useful and make your code more efficient, is that when implementing classes, the programmer has control over the whole class as well as any subclasses.

 Additionally, as when used in Assignment 1, classes can be used to make a general class, with more specific subclasses. In this way, a general class for a game state, can have numerous subclasses for specific games, such as tic-tac-toe, subtract square or even connect 4. While the game state for these games are unique and different in many ways, they do share some similar attributes and are the same "type" of game. They are both 2 player, sequential, zero sum games, and having a general game state to reflect this is quite useful. Using object-oriented programming is very useful and has numerous advantages.

Monday, February 9, 2015

Week 4: Tracing Recursion

Last week in class, we learned about recursion. A strange way in which a function can call itself in the function. Recursion is strange in that the function calls itself. This would seem as though the function is incomplete or that an infinite loop would be created. However, recursion works, and in order to understand it, smaller and simple examples must be examined and understood. That is what we did in class. In order for us to understand recursion, we must be able to examine the function and how the function works with simple examples, and then other more complex examples. In this way, recursion can be better understood.

I had trouble understanding recursion, when it was first introduced. However, tracing the examples really helps to explain recursion. Similarly, I had trouble implementing recursion, a trouble I may still be suffering. I understand the concept of recursion quite well, thanks to the examples. However, actually having to implement recursion is something I find difficult. Understanding when exactly I should use recursion and the way in which it should be implemented is something I struggled with that week. There seems to be a sort of "formula" or "form" in writing recursion code, where there is an "if...else" statement. The "else" statement is usually important for (tracing) the simplest recursion call. The "if" statement is harder to write, and where I have the most difficulty. Hopefully, practicing and writing more code should help me overcome this problem. Also, I plan on researching recursion more and looking at recursion code more, in order that I familiarize myself with recursion.

Additionally, in lab, this week I used the python visualizer to trace recursion calls. This helped to solidify how and why recursion works. This also made it easier for me to understand the way the function is implemented. All in all, tracing code to understand the concept and practicing problems to implement it, will give me a better understanding of recursion.

Tuesday, February 3, 2015

Week 1-3: ADTs, Stack, and Subclasses

The first few weeks of CSC148 have come and gone, and already we have covered ADTs, Stacks, and Subclasses. Assignment 1, was due Thursday, January 29 and in it I had to implement the concepts (particularly the concept of Inheritance and Subclasses) learned in class. I learned how to raise an Implementation Error and how to create Stacks. I also learned that about how to create a Subclass and what it means for the subclass to inherit attributes of the class.

It was difficult to implement the concepts learned in class. A stack in particular is something I had trouble understanding at first. However after reviewing the material, I am now confident in the material. One achievement for this week is my completion of the Assignment 1. As mentioned earlier, in Assignment 1 I had to implement the concept of Inheritance and Subclasses. I didn't find that particularly difficult. However reading the objective of the Assignment and figuring a way to complete it was difficult. I found it hard to begin and trouble understanding how the game would play, but after a good night's rest, I realized that the game would play by using the code: "if __name__ == '__main__'. Once I realized this, it was only a matter of coding the actual game.

I understood the way to go about programming the code, however, I did run across a few bugs. I was unable to actually get the game to run smoothly with no errors, probably because of the helper function I created to keep track of the legal moves was not working for all cases. However, despite the setback and failure, I did learn a lot through this assignment. Unlike the previous computer science course I took last year (CSC108), where the professors made the assignments as easy as possible, and told you what functions to complete and how to go about completing them, this was quite harder. The handout did not say what functions to write or how to write the subclasses. It was difficult getting started, especially since it seems like an overwhelming and difficult task. Once I got started, however, it wasn't as hard a task as I expected it to be.

Saturday, January 24, 2015

Why Geeks Need to Know How to Write


Computer programmers, i.e Geeks, need to know how to write. Its an important aspect of programming that doesn't get much consideration, and isn't really acknowledged. In fact, you're probably wondering why geeks need to know how to write, when they are usually dealing more with mathematical concepts, numbers, and code, not English: spelling or grammar.

One reason, is so that a programmer, can be able to keep a thorough and concise debugging journal. Debugging journals are very crucial, especially when dealing with difficult and time consuming bugs. A debugging journal helps geeks keep track of all the the work they've done so far to fix the problem and also keeps the programmer on track. By logging in each attempt and asking themselves questions about the bug, it is easier and more organized approach to debugging. Additionally, this debugging journal, can help the geek next time they face the same or a similar problem. This also ensures that the programmer knows what the actual problem was, and understands how to fix it, if it were to happen again.

Another reason, programmers should know how to write is so that they may be able to explain and communicate their ideas fully and more clearly. In fact, when a programmer is not able to program their idea efficiently, a thorough explanation in English may be the difference between actually completing the project or dumping it. It is through, explanations and persuasion, that geeks are able to showcase their ideas, and encourage others to help implement it.

A final reason, geeks should write is so that they may be able to write proper documentation for their code. The difference between a good code and a great code is its documentation. This is also the difference between code that can only be implemented once or by its programmer, and code that can be reused and improved upon by other programmers. With documentation, such as a proper and concise docstring, that can explain the code and its usage, code can be shared and expanded upon by others. All in all, geeks should write. Not only does it improve their code, but through writing, geeks can raise awareness and support for their project, as well as make debugging more organized and easier.